goatslacker / alt-devtool

180 stars 15 forks source link

Failure with createStore() #20

Closed jareware closed 9 years ago

jareware commented 9 years ago

If I define a store like:

import immutable from 'alt/utils/ImmutableUtil';

alt.createStore(immutable({
  displayName: 'derpStore',
  state: new Immutable.Map({
    count: 0
  }),
  reduce: (state, payload) => {
    return state.updateIn([ 'count' ], x => x + 1);
  }
}));

I get:

TypeError: Cannot read property 'onSerialize' of undefined

from here.

If I use alt.addStore(StoreClass) with the same config patched into the prototype it works as expected. Also the immutable-util works as expected, because when I takeSnapshot('derpStore') I get a sensible serialization.

Ideas?

jareware commented 9 years ago

Well, actually it looks like this config access should actually use store.StoreModel.config like snapshot() does, and it sorta accidentally works with class-based stores because the config is available on the prototype chain.

jbroadice commented 9 years ago

This is also happening when using alt-router.

goatslacker commented 9 years ago

Fixed in alt@0.17.8.

goatslacker commented 9 years ago

https://github.com/goatslacker/alt/commit/d72eb9d633e313bf1f3cdab546d2a3a17e762421

jareware commented 9 years ago

Very nice, thanks!