javascript - immutable.js & react.js setState clears prototype of the object -


i have following code in component:

constructor() {     this.state = immutable.fromjs({             user : {                 waschanged : false,                 firstname : false,                 lastname : false,                 address : {                     street : false,                 }             }         }); } onedit({target: {dataset: {target}}}, value) {       this.setstate(function (prevstate) {           return prevstate.setin(['user', target], value);         });   } render() {     var user = this.state.get('user').tojs();     ... } 

the problem when try update value in onedit see prevstate has different prototype set. don't understand why or doing wrong. see in console

> object.getprototypeof(this.state) src_map__map {@@__immutable_map__@@: true}  > object.getprototypeof(prevstate) object {} 

after state has been changed goes render of course can't find get function or immutable

using react addons 0.13.3.

put key on state.

this.state = {   data: immutable... }; 

currently reason can't use immutable object state same reason can't this.state = 7: it's not plain javascript object.

roughly operation looks this:

react.component.prototype.setstate = (changes) => {   batchupdate(() => {     // copies own properties state new object     // , own properties changes new object     var nextstate = object.assign({}, state, changes);      this.componentwillupdate(...);     this.state = nextstate;     queuedomupdatestuff(this.render(), () => this.componentdidupdate());   }); }; 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -