Closed daoquangphuong closed 7 years ago
Hi @daoquangphuong
Seems to work for me
http://jsbin.com/mubucizope/1/edit?js,console
What's exactly failing?
Cheers, Javi
ok. i have one "socket.io-client@1.4.5", with event:
var store = new Freezer({})
socket_client.on('updateStore', function (data) {
// add clone data in this line
var state = store.get();
Object.keys(data).forEach(function (name) {
state = state.set(name, data[name]);
})
});
store.on('update',function(){
console.log(store.get().toJS()) // <- working
console.log(store.get().a.toJS()) // <- toJS func is undefined in here
})
and i emit from server:
socket_server.emit('updateStore',{a:{b:'c'}})
///// working normal in my chrome browser. but not working in node-webkit v 0.12.3 base on Chromium 41.0.2272.76
if i downgrade to freezer-js@0.10.0 -> woking normal or clone data before set in store: data = JSON.parse(JSON.stringify(data)) -> woking normal
I suspect that store.get().a
is not a plain JS but an instance of some class.
Try to create your store like:
var store = new Freezer({},{freezeInstances: true});
That should parse class instances and add freezer methods to them.
Please check toJS func in freezer-js@0.11.0