featL synchronize params and state
This commit is contained in:
parent
9e74aaf7e7
commit
5b0e8092d2
|
@ -40,11 +40,10 @@ class EntityListBase {
|
|||
}
|
||||
}
|
||||
else {
|
||||
// New entity. Create with change as traits' state.
|
||||
const traits = mapValues(change[uuid], (changeTraits) => ({
|
||||
state: changeTraits,
|
||||
}));
|
||||
const newEntity = create().fromJSON({traits});
|
||||
// New entity. Create with change as traits.
|
||||
const newEntity = create().fromJSON({
|
||||
traits: change[uuid],
|
||||
});
|
||||
this.addEntity(newEntity);
|
||||
this.uuidMap_PRIVATE[uuid] = newEntity.instanceUuid;
|
||||
}
|
||||
|
|
|
@ -12,17 +12,22 @@ export class Trait {
|
|||
}
|
||||
|
||||
acceptStateChange(change) {
|
||||
const undefinedProperties = {};
|
||||
for (const key in change) {
|
||||
const value = change[key];
|
||||
if (key in this.entity) {
|
||||
this.entity[key] = value;
|
||||
}
|
||||
else {
|
||||
undefinedProperties[key] = value;
|
||||
}
|
||||
if (change.params) {
|
||||
this.params = this.params.merge(I.fromJS(change.params));
|
||||
}
|
||||
if (change.state) {
|
||||
const undefinedProperties = {};
|
||||
for (const key in change.state) {
|
||||
const value = change.state[key];
|
||||
if (key in this.entity) {
|
||||
this.entity[key] = value;
|
||||
}
|
||||
else {
|
||||
undefinedProperties[key] = value;
|
||||
}
|
||||
}
|
||||
this.state = this.state.merge(undefinedProperties);
|
||||
}
|
||||
this.state = this.state.merge(undefinedProperties);
|
||||
}
|
||||
|
||||
actions() {
|
||||
|
|
|
@ -47,9 +47,11 @@ export class Traits {
|
|||
this.addTrait(type, change[type]);
|
||||
instance = this.traits_PRIVATE[type];
|
||||
}
|
||||
// Accept state.
|
||||
instance.acceptStateChange(change[type]);
|
||||
this.state_PRIVATE = this.state_PRIVATE.set(type, instance.state);
|
||||
else {
|
||||
// Accept state.
|
||||
instance.acceptStateChange(change[type]);
|
||||
}
|
||||
this._setInstanceState(type, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +116,7 @@ export class Traits {
|
|||
this.properties_PRIVATE[key] = properties[key];
|
||||
}
|
||||
// Add state.
|
||||
this.state_PRIVATE = this.state_PRIVATE.set(type, instance.state);
|
||||
this._setInstanceState(type, instance);
|
||||
// Track trait.
|
||||
this.traits_PRIVATE[type] = instance;
|
||||
this.entity_PRIVATE.emit('traitAdded', instance);
|
||||
|
@ -236,6 +238,14 @@ export class Traits {
|
|||
types.forEach((type) => this.removeTrait(type));
|
||||
}
|
||||
|
||||
_setInstanceState(type, instance) {
|
||||
const state = this.state_PRIVATE;
|
||||
let map = state.has(type) ? state.get(type) : I.Map();
|
||||
map = map.set('state', instance.state);
|
||||
map = map.set('params', instance.params);
|
||||
this.state_PRIVATE = this.state_PRIVATE.set(type, map);
|
||||
}
|
||||
|
||||
setProperty(property, value, receiver) {
|
||||
if (property in this.properties_PRIVATE) {
|
||||
const instance = this.properties_PRIVATE[property].instance;
|
||||
|
@ -246,7 +256,7 @@ export class Traits {
|
|||
);
|
||||
}
|
||||
instance[property] = value;
|
||||
this.state_PRIVATE = this.state_PRIVATE.set(type, instance.state);
|
||||
this._setInstanceState(type, instance);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user