goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

alt.bootstrap not working on server side #652

Closed carlitux closed 8 years ago

carlitux commented 8 years ago

Hi I have code on server side sending this string to alt.bootstrap:

'{"UsersStore":{"loggedInUser":{"_id":"users/28156269660","_key":"28156269660","_rev":"28319650908","is_active":true,"email":"carlitos.kyo@gmail.com","full_name":"Luis Carlos Cruz Carballo"}}}'

but when printing the state in component I am getting:

{
  size: 1,
  _root: ArrayMapNode { ownerID: OwnerID {}, entries: [ [Object] ] },
  __ownerID: undefined,
  __hash: undefined,
  __altered: false }

I am using same string on browser to bootstrap and it is rendered as I need, but server is not rendering the same.

Any idea why on server bootstrap is not filling the Stores?

carlitux commented 8 years ago

This is only happening when using immutable on stores... If I remove decorator, all works as expected.

jdlehman commented 8 years ago

The immutable decorator uses immutable.js to make your store use immutable data structures. These immutable data structures are passed back to the view, so what you are seeing is correct.

There are a couple of things you can do. You can call .toJS() on the immutable structure you are getting back in your component to convert it to a POJO, if you find that easier to work with. You can also use the getters that the immutable.js library provides to read data from the immutable object. Lastly, you can remove the decorator entirely as you already noted.