local storage - breezejs importEntities fail "this key is already attached" -


i have spa (hot towel template) , use window.localstore keep data in browser. used export/import breeze 1.3.3 , worked while cleared browser history in first time of test, later didn't clear browser history , worked fine again export/import entities window.localstore. later after of many tests browser show next error:

script5022: key attached: project:#solution.project--1 

the error appeared when had close browser , didn't clear browser history first time of test.

when load spa, first load data of window.localstore , use importentities function of breeze.

the spa loaded manager.getchanges().length result 0 (0) , correct, later call next function setlocalstoragetomanager load pending changes in actual manager.

function setlocalstoragetomanager(manager) { var name = 'pendingchangesonlocalstorage'; if (window.localstorage.length > 0) {     var importdata = window.localstorage.getitem(name);     if (importdata) {         return manager.importentities(importdata,             { mergestrategy: breeze.mergestrategy.preservechanges });      } else {         return manager;     }  } else {     return manager; } } 

the error appeared here:

manager.importentities(importdata,{ mergestrategy: breeze.mergestrategy.preservechanges });

for example in test window.localstore return 2 entities id:-1 , id:-2, in breeze.debug.js in next function read first entity id:-1, later read second entity id:-1 again , error this key attached:

proto.attachentity = function (entity, entitystate) {     // entity should have aspect.     var ix;     var aspect = entity.entityaspect;     var keyingroup = aspect.getkey()._keyingroup;     ix = this._indexmap[keyingroup];     if (ix >= 0) {         if (this._entities[ix] === entity) { //-->error here             return entity;         }         throw new error("this key attached: " + aspect.getkey());     }      if (this._emptyindexes.length === 0) {         ix = this._entities.push(entity) - 1;     } else {         ix = this._emptyindexes.pop();         this._entities[ix] = entity;     }     this._indexmap[keyingroup] = ix;     aspect.entitystate = entitystate;     aspect.entitygroup = this;     aspect.entitymanager = this.entitymanager;     return entity; }; 

the error appeared in third test (export data localstorage , import data) without delete browser history, tested in ie10, google chrome version 27.0.1453.93 m , firefox 21.0.

please appreciated


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -