Last active
September 9, 2016 12:27
-
-
Save taras/48839269bcda7ffc44d098c1b5f1bee2 to your computer and use it in GitHub Desktop.
This gist shows what Microstate helpers might look like using a callback to notify helper of change.
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 StateHelper from 'ember-microstates/helpers/state'; | |
import { Bool } from 'microstates'; | |
export default StateHelper.extend({ | |
construct(params, hash, onTransition) { | |
return new Bool(params, onTransition); | |
} | |
}); |
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 StateHelper from 'ember-microstates/helpers/state'; | |
import { List } from 'microstates'; | |
export default StateHelper.extend({ | |
construct(params, hash, onTransition) { | |
return new List(params, onTransition); | |
} | |
}); |
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 StateHelper from 'ember-microstates/helpers/state'; | |
import { Num } from 'microstates'; | |
export default StateHelper.extend({ | |
construct([value], hash, onTransition) { | |
return new Num(value, onTransition); | |
} | |
}); |
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 Ember from 'ember'; | |
import { State } from 'microstates'; | |
export default Ember.Helper.extend({ | |
construct([Microstate = State], hash, onTransition) { | |
return new Microstate(hash, onTransition); | |
}, | |
compute(params, hash) { | |
if (this._update) { | |
this._update = false; | |
return this._microstate; | |
} | |
let onTransition = (microstate) => { | |
this._update = true; | |
this._microstate = microstate; | |
this.recompute(); | |
}; | |
return this._microstate = this.construct(params, hash, onTransition); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment