Skip to content

Commit

Permalink
wat
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Jun 26, 2015
1 parent f4bb812 commit 89fe4d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"no-wrap-func": 2,
"no-underscore-dangle": 0,
"one-var": [2, "never"],
"padded-blocks": [2, "never"],
"padded-blocks": [0],
"semi-spacing": [2, {
"before": false,
"after": true
Expand Down
12 changes: 7 additions & 5 deletions foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const alt = new Alt()
const actions = alt.generateActions('foo')

class MyStore extends Store {
constructor() {
super(alt, {
displayName: 'MyStore'
})
constructor(one, two, three) {
super(alt)
// displayName: 'MyStore'
// })

this.state = { x: 1 }

Expand All @@ -18,7 +18,9 @@ class MyStore extends Store {
}
}

const store = new MyStore()
//export default alt.registerStore(1, 2, 3)(MyStore)

const store = alt.registerStore()(MyStore)

store.listen(state => console.log('CHANGED', state))

Expand Down
12 changes: 12 additions & 0 deletions src/alt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class Alt {
return makeAction(this, 'global', name, implementation, obj)
}

registerStore(...args) {
return (TheStore) => {
const store = new TheStore(...args)
// meh
StateFunctions.saveInitialSnapshot(store.state, store.displayName)

// double meh
this.stores[store.displayName] = store
return store
}
}

createActions(ActionsClass, exportObj = {}, ...argsForConstructor) {
const actions = {}
const key = utils.uid(
Expand Down
27 changes: 12 additions & 15 deletions src/alt/store/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as utils from '../utils/AltUtils'
import * as fn from '../../utils/functions'
// import * as StateFunctions from '../utils/StateFunctions'
import transmitter from 'transmitter'


class Store {
constructor(alt, config) {
this.config = fn.assign({
getState(state) {
return fn.assign({}, state)
},
setState: fn.assign
}, config)

constructor(alt) {

this.displayName = this.config.displayName || this.displayName || this.name || ''

// XXX well then how do I make sure this gets set? Ideally as a static prop in the derived class
// this.config = fn.assign({
// getState(state) {
// return fn.assign({}, state)
// },
// setState: fn.assign
// }, config)

this.boundListeners = []
this.lifecycleEvents = {}
this.actionListeners = {}
Expand Down Expand Up @@ -81,8 +85,6 @@ class Store {
})
})

// this.lifecycle('init')

if (this.alt.stores[this.displayName] || !this.displayName) {
if (this.alt.stores[this.displayName]) {
utils.warn(
Expand All @@ -95,11 +97,6 @@ class Store {

this.displayName = utils.uid(this.alt.stores, this.displayName)
}

// XXX this needs to happen after this.state is set!
// StateFunctions.saveInitialSnapshot(this.state, this.displayName)

this.alt.stores[this.displayName] = this
}

bindAction(symbol, handler) {
Expand Down

0 comments on commit 89fe4d1

Please sign in to comment.