javascript - $localStorage value got change with fabric js -


i saving polygon value inside angular $localstorage .

once fabric js draw object . $localstorage changed.

var arr = [{         x: 81,         y: 58     }, {         x: 221,         y: 23     }, {         x: 247,         y: 158     }, {         x: 100,         y: 219     }, {         x: 81,         y: 58     }];      if(!$localstorage.mask)       $localstorage.mask = arr; 

is bug ?

here plunker

indeed, fabricjs seems modify given points array internal purposes (i.e. offset), in piece of code (from https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.5.0/fabric.js):

...     //misko321: reference of minx, miny, width , height   _calcdimensions: function() {        var points = this.points,           minx = min(points, 'x'),           miny = min(points, 'y'),           maxx = max(points, 'x'),           maxy = max(points, 'y');        this.width = (maxx - minx) || 0;       this.height = (maxy - miny) || 0;        this.minx = minx || 0,       this.miny = miny || 0;     },    _applypointoffset: function() {       // change points offset polygon bounding box       // executed 1 time       this.points.foreach(function(p) {         p.x -= (this.minx + this.width / 2);         p.y -= (this.miny + this.height / 2);       }, this);     },  ... 

together fact ngstorage observes changes added objects, updates modified (internally fabric.js) coordinates.

the cleanest solution comes mind @ moment copy arr object (ref. most elegant way clone javascript object) , send 1 of objects ngstorage , other 1 fabricjs.

nevertheless, nice, if ngstorage supported sort of freeze() method, disable angularjs watch on object, preventing further modifications.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -