Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created July 28, 2015 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmccray/c5b6c69c1653b941ccd7 to your computer and use it in GitHub Desktop.
Save mattmccray/c5b6c69c1653b941ccd7 to your computer and use it in GitHub Desktop.
Immobservable?
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'
})
@mattmccray
Copy link
Author

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's true.

@mweststrate
Copy link

👍
See: mobxjs/mobx#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment