Add destroy to reactive-dict

This will clear the dict and unregister the dict for migration.
This commit is contained in:
Simon Fridlund
2017-06-11 18:47:56 +02:00
parent 0d7ce023e0
commit a89438cccd
2 changed files with 12 additions and 2 deletions

View File

@@ -4,8 +4,11 @@ ReactiveDict._migratedDictData = {}; // name -> data
ReactiveDict._dictsToMigrate = {}; // name -> ReactiveDict
ReactiveDict._loadMigratedDict = function (dictName) {
if (_.has(ReactiveDict._migratedDictData, dictName))
return ReactiveDict._migratedDictData[dictName];
if (_.has(ReactiveDict._migratedDictData, dictName)) {
const data = ReactiveDict._migratedDictData[dictName];
delete ReactiveDict._migratedDictData[dictName];
return data;
}
return null;
};

View File

@@ -210,6 +210,13 @@ export class ReactiveDict {
}
return didRemove;
}
destroy() {
this.clear();
if (this.name && _.has(ReactiveDict._dictsToMigrate, this.name)) {
delete ReactiveDict._dictsToMigrate[this.name];
}
}
_setObject(object) {
_.each(object, (value, key) => {