Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Created October 31, 2016 10:15
Show Gist options
  • Save jackcallister/9b2f9d947f135962b81f424fa2f07ede to your computer and use it in GitHub Desktop.
Save jackcallister/9b2f9d947f135962b81f424fa2f07ede to your computer and use it in GitHub Desktop.
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
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