Created
October 31, 2016 10:15
-
-
Save jackcallister/9b2f9d947f135962b81f424fa2f07ede to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { extendObservable, action } = require('mobx') | |
class Store { | |
constructor(observables = {}, actions = {}, props = {}) { | |
extendObservable(this, props) | |
Object.keys(actions).forEach((key) => { | |
this[key] = action(actions[key]) | |
}) | |
Object.assign(this, props) | |
} | |
} | |
function createStore(observables, actions, props) { | |
return new Store(observables, actions, props) | |
} | |
module.exports = createStore |
This file contains hidden or 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
const observables = { | |
count: 1, | |
computedFunc: () => { | |
return this.count + 1 | |
} | |
} | |
const actions = { | |
increment: () => { | |
this.count += 1 | |
} | |
} | |
const props = { | |
staticProperty: 'I am static', | |
dynamicFunc: (randomNumber) => { | |
return this.count + randomNumber | |
} | |
} | |
const store = createStore(observables, actions, props) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment