React.js、redux、Immutable.jsを使ってるのですが、reduxのドキュメントを見ると、immutable.jsの使用を猛烈推薦する一方で、下層の単にビューを表示するだけのコンポーネント(関数)では使うな、絶対使うな!といっております。
理由としてはビューをレンダーするだけのコンポーネントはpure function(参照透過性でしたっけ?)であるべきだからということなのですが、immutable.jsのような外部ライブラリに依存してしまうのも純粋関数にならなくなるのでしょうか?
外部の状態に依存する関数は純粋関数の条件に満たなかったと自分の浅い知識では記憶していますが、外部ライブラリに依存もダメですか?純粋関数どうこうっていうより、外部ライブラリ使うと関数の引数から外部ライブラリに依存したオブジェクトやインスタンスを渡したとしても、テストしづらくなるってことでしょうか?
http://redux.js.org/docs/recipes/UsingImmutableJS.html
Never use Immutable.JS in your Dumb Components
Your dumb components should be pure; that is, they should produce the same output given the same input, and have no external dependencies. If you pass such a component an Immutable.JS object as a prop, you make it dependent upon Immutable.JS to extract the prop’s value and otherwise manipulate it.
Such a dependency renders the component impure, makes testing the component more difficult, and makes reusing and refactoring the component unnecessarily difficult.
Such a dependency renders the component impure, makes testing the component more difficult,
テストがしづらくなるというのはモックのインスタンス作らないといけなくなったりしてわかりますが、外部への依存性がコンポーネントをimpureにするってのは何故なのでしょう?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/10/08 06:06
2017/10/08 06:14
退会済みユーザー
2017/10/08 06:26
退会済みユーザー
2017/10/08 06:31
退会済みユーザー
2017/10/09 05:51
2017/10/10 23:38
退会済みユーザー
2017/10/11 00:01