diff --git a/docs/utils/immutable.md b/docs/utils/immutable.md index 9c93f47a..a500a1fb 100644 --- a/docs/utils/immutable.md +++ b/docs/utils/immutable.md @@ -97,7 +97,7 @@ Last but not least, snapshots and bootstrapping just works when you're using thi #### `Record` -One of the easiest ways to start getting some of the benefits of immutable is to take advantage of Immutable's [`Record`](http://facebook.github.io/immutable-js/docs/#/Record) types. This method will result in the smallest changes for existing projects. You can read more about them on Facebook's docs, but the best thing about Records is that they enable you to access values the same way you would from a normal JS object (`object.prop`). This means no changes to the view code using the immutable data and our changes only occur in store methods that return data to the view. +One of the easiest ways to start getting some of the benefits of immutable is to take advantage of Immutable's [`Record`](http://facebook.github.io/immutable-js/docs/#/Record) types. This method will result in the smallest changes for existing projects. You can read more about them on Facebook's docs, but the best thing about Records is that they enable you to access values the same way you would from a normal JS object (`object.prop`). This means no changes to the view code using the immutable data and our changes only occur in store methods that return data to the view. Here is an example of how a Record can be used: @@ -133,6 +133,16 @@ class MyComponent extends Component { } ``` +Keep in mind that your listeners to store changes will keep receiving the _mutable_ version of the store state because of the implemenation of [`emitChange`](https://github.com/goatslacker/alt/blob/f4de73d6c5d71b4edc7c89c8eddef04dd0be1e6a/src/store/AltStore.js#L22) + +```js + MyStore.listen(this.onMyStoreChange); + ... + onMyStoreChange(storeNewState){ + //storeNewState is not a Record and therefore mutable! + } +``` + #### `fromJS` Immutable has a nice helper, [`fromJS`](http://facebook.github.io/immutable-js/docs/#/fromJS) that allows us to convert JS object/arrays to immutable [`Map`s](http://facebook.github.io/immutable-js/docs/#/Map) and [`List`s](http://facebook.github.io/immutable-js/docs/#/List). This is an easy way to convert plain JS store data to immutable data structures before sending to the view. Unlike the "Record method" described above, you must remember to use getters to access data within these immutable objects.