Skip to content

Commit e6f64bc

Browse files
committed
Load() make copy of layout
* before we modify the passed in layout, we make a (shallow) copy so sort() doesn't affect user's data * also removed passing removeDOM to onChange() callback as we have node._removeDOM
1 parent d606790 commit e6f64bc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Change log
5656
## 4.1.0-dev
5757

5858
- fix [#1704](https://github.com/gridstack/gridstack.js/issues/1704) scrollbar fix broken in 4.x
59-
- add [#1682](https://github.com/gridstack/gridstack.js/issues/1682) `addWidget()` now supports recursive grids like init/addGrid() does.
59+
- add [#1682](https://github.com/gridstack/gridstack.js/issues/1682) `addWidget()` now supports nested grids like init/addGrid() does.
6060

6161
## 4.1.0 (2021-4-7)
6262

src/gridstack-engine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export class GridStackEngine {
484484
// don't use 'faster' .splice(findIndex(),1) in case node isn't in our list, or in multiple times.
485485
this.nodes = this.nodes.filter(n => n !== node);
486486
return this._packNodes()
487-
._notify(node, removeDOM);
487+
._notify(node);
488488
}
489489

490490
public removeAll(removeDOM = true): GridStackEngine {
@@ -493,7 +493,7 @@ export class GridStackEngine {
493493
removeDOM && this.nodes.forEach(n => n._removeDOM = true); // let CB remove actual HTML (used to set _id to null, but then we loose layout info)
494494
this.removedNodes = this.nodes;
495495
this.nodes = [];
496-
return this._notify(this.removedNodes, removeDOM);
496+
return this._notify(this.removedNodes);
497497
}
498498

499499
/** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.

src/gridstack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ export class GridStack {
314314
column: this.opts.column,
315315
float: this.opts.float,
316316
maxRow: this.opts.maxRow,
317-
onChange: (cbNodes, removeDOM = true) => {
317+
onChange: (cbNodes) => {
318318
let maxH = 0;
319319
this.engine.nodes.forEach(n => { maxH = Math.max(maxH, n.y + n.h) });
320320
cbNodes.forEach(n => {
321321
let el = n.el;
322-
if (removeDOM && n._removeDOM) { // TODO: do we need to pass 'removeDOM' ?
322+
if (n._removeDOM) {
323323
if (el) el.remove();
324324
delete n._removeDOM;
325325
} else {
@@ -498,7 +498,7 @@ export class GridStack {
498498
* see http://gridstackjs.com/demo/serialization.html
499499
**/
500500
public load(layout: GridStackWidget[], addAndRemove: boolean | ((g: GridStack, w: GridStackWidget, add: boolean) => GridItemHTMLElement) = true): GridStack {
501-
let items = GridStack.Utils.sort(layout, -1, this._prevColumn || this.opts.column);
501+
let items = GridStack.Utils.sort([...layout], -1, this._prevColumn || this.opts.column); // make copy before we mod/sort
502502
this._insertNotAppend = true; // since create in reverse order...
503503

504504
// if we're loading a layout into 1 column (_prevColumn is set only when going to 1) and items don't fit, make sure to save

0 commit comments

Comments
 (0)