Created
July 28, 2015 18:27
-
-
Save mattmccray/c5b6c69c1653b941ccd7 to your computer and use it in GitHub Desktop.
Immobservable?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mobservable from 'mobservable/immutable' // Separate module needed? | |
// Not sure, but basically we need | |
// to mark it as immutable somehow | |
let user = mobservable.fromJson({ | |
name: 'Matt', | |
age: 'NunYoBiznis' | |
}) | |
user.name //= 'Matt' | |
user.name = 'Matthew' // ignored | |
user.name //= 'Matt' | |
mobservable.transaction(() => { | |
user.name = 'Matthew' // applied | |
user.name //= 'Matthew' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love the mechanisms and simplicity of observers, but sometimes it'd be nice to have some simple -- I hesitate to use the term 'immutability', since that carries some baggage, but frankly -- immutability. :-)
For systems (or teams) of a certain size, it becomes useful to be able to strictly control where mutations can occur (usually in a controller/flux store).
How would this work? Well I'm not exactly sure, but my naive idea is that any setter created by the immutable observable would check for some sort of
inTransaction
flag and only do the update and trigger the change if it'strue
.