Skip to content

Instantly share code, notes, and snippets.

@goatslacker
Created March 27, 2015 20:56
Show Gist options
  • Save goatslacker/2dceff389071418de68f to your computer and use it in GitHub Desktop.
Save goatslacker/2dceff389071418de68f to your computer and use it in GitHub Desktop.
const ImmutableUtil = require('./utils/ImmutableUtil')
const Immutable = require('immutable')
const Alt = require('./')
const alt = new Alt()
const actions = alt.generateActions('fire')
//function ImmutableStore() {
// this.handleFoo = function (x) {
// this.setState('foo', x)
// }.bind(this)
//
// this.bindListeners({
// handleFoo: actions.fire
// })
const ImmutableStore = {
displayName: 'ImmutableStore',
state: {
foo: 'hello'
},
bindListeners: {
handleFoo: actions.fire
},
handleFoo: function (x) {
this.setState(this.state.set('foo', x))
this.setState('foo', x)
}
}
const store = ImmutableUtil.createStore(alt, ImmutableStore, 'ImmutableStore')
console.log(store.getState().toJS().foo, 'foo has not been defined')
actions.fire('lol')
console.log(store.getState().toJS().foo === 'lol', 'foo has been defined')
var newMap = Immutable.Map({})
console.log(newMap.foo, 'references do not leak')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment