Make it to make it

いろいろ作ってアウトプットするブログ

2019-06-01から1ヶ月間の記事一覧

TypeScript学習5(Classes)

Classes Blueprint to create an object with some fields (values) and methods (functions) to represent a 'thing'. class Vehicle { drive(): void { console.log('chugga chugga'); } honk(): void { console.log('beep'); } } class Car extends Vehic…

TypeScript学習4(Typed objects: Interfaces)

Interfaces Creates a new type, describing the property names and value types of an object 例えば、今まで学んだことを利用して次のように型定義を行うと、コードが長くなってしまって可読性も低くなる。 const oldCivic = { name: 'civic', year: 200,…

TypeScript学習3(Typed arrays)

TSでarrayを扱う上で重要なポイント TS can do type inference when extracting values from an array TS can prevent us from adding incompatible values to the array We can get help with map, forEach, reduce, functions Flexible - arrays can still…

TypeScript学習2(ファンクション周りでの扱い)

ファンクション周りでのannotations/inference使い分け Type annotations for functions Code we add to tell TS what type of arguments a function will receive and what type of values it will return. Type inference for functions TS tries to figur…

TypeScript学習1(Type annotations, Type inference)

重要な概念を2つほど。 Type annotations / Type inference Type annotations Code we add to tell TypeScript what type of value a variable will refer to Type inference TypeScript tries to figure out what type of value a variable refers to 前者…

React学習7(機能追加)

外部データから取得して一覧表示して、Like付けたり削除できたりできるところまで。 ファイル構成 . ├── App.js ├── Vidly.jsx ├── components │ ├── atoms │ │ └── Like.jsx │ └── molecules │ └── Movies.jsx ├── data │ └── services │ ├── fakeGenreServ…

React学習6(リファクタリング)

カウンターコンポーネントを最終的にリファクタリングしたもの。 ファイル構成 . ├── App.jsx ├── components │ ├── Counter.jsx │ ├── Counters.jsx │ └── Navbar.jsx └── index.js ファイルの中身 App.jsx import React, { Component } from 'react' impor…

React学習5(lifecycle hooks)

Lifecycle Hooks ReactのLifecycle hooksでよく用いられるものはだいたい次の通り。 Mount constructor render componentDidMount Update render componentDidUpdate Unmount componentDidUnmount Mounting phase constructor, render, componentDidMountの…

React学習4(functional component)

React復習がてら要点をまとめていく。 React学習3で学んだところから、さらに階層深くコンポーネント構成をする、次のようなケースの場合。 . ├── App.jsx ├── components │ ├── Counter.jsx │ ├── Counters.jsx │ └── Navbar.jsx └── index.js Objectやargu…

React学習3(props, single source of truth, controlled component)

React復習がてら要点をまとめていく。 Single source of truth Reactでの状態(state)管理は、一つのソースで行わないといけない。これがSingle source of truthと言われるものである。 あるlocal stateを持ったコンポーネントを複数読み込んでその親もstat…

React学習2(外部データの読み込みと表示)

React復習がてら要点をまとめていく。 外部ファイルの配列形式のデータを読み込んできて、画面に表示する例。 要点整理 Conditional renderingをするときは、returnするブロックを別メソッドで分けておくとやりやすい。 読み込むデータに対してgetter, sette…

React学習1(Prettier+ESLint, state, computed/method)

React復習がてら要点をまとめていく。 環境構築 Starter Kit create-react-appをグローバルでインストールして、スターターファイルを立ち上げる。 create-react-app counter-app ちなみに、スターター系は公式ドキュメントStarter Kits – Reactにもまとめら…

TypeScriptハンズオン2(module化とimport, tsc, tsconfig)

モジュールでの型宣言とimport ES Moduleで他ファイルに型宣言したものを読み込ませることができる。 // Interfaces.ts export interface Person { name: string; age?: number; } enum Job { WebDev, WebDesigner, PM } export default Job; // index.ts im…

TypeScriptハンズオン1(default param, implicit types, union types, interface, enum, class)

デフォルト引数の活用 次のようなファンクションを定義する。 const sayWord = (word: string): string => { console.log(word); return word; }; sayWord('hoge'); sayWord(); TSでは引数と返り値に対してこのような型指定の形式を取る。 するとVanillaJSの…

TypeScriptミニマム実行環境構築

JavaScriptの型付けは動的に行われているので、暗黙の型変換や型の認識(Truthy / Falsy)などが行われてしまう。 そこで必要なのが、JavaScriptのスーパーセット(Superset)であるTypeScriptによる静的型付けである。 ParcelによるTypeScript実行環境の構…

Webpackをゼロから学ぶ(その3)

グローバル変数のファイル間共有 jQueryなどのライブラリをJSファイル側で毎回読みこむのが面倒であるときに有効なのが、 webpack.common.js に webpack モジュールからプラグインを読み込ませる方法だ。 webpack.common.js const webpack = require('webpac…

Webpackをゼロから学ぶ(その2)

Tree shaking 使用していないdead codeを読み込むことはファイルサイズの増大につながり、適切ではないであろう。 Webpackにおいて、例えばライブラリやファンクションを読み込んでいるのに一切使っていない場合は、 デフォルトのproductionモードでは、dist…

Webpackをゼロから学ぶ(その1)

WebpackなどのフロントエンドDevOps的な分野は、なかなか面倒なイメージで今まで避けてきた部分だったので、改めてゼロからしっかりと学んでみる。 Webpack学習の問題点 初学者にとっていきなり理解するのは難しい。実践が必要 無関係なこともブラックボック…