MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / cacheLayout

Method cacheLayout

src/gridstack-engine.ts:1199–1212  ·  view source on GitHub ↗

* call to cache the given layout internally to the given location so we can restore back when column changes size * @param nodes list of nodes * @param column corresponding column index to save it under * @param clear if true, will force other caches to be removed (default false)

(nodes: GridStackNode[], column: number, clear = false)

Source from the content-addressed store, hash-verified

1197 * @param clear if true, will force other caches to be removed (default false)
1198 */
1199 public cacheLayout(nodes: GridStackNode[], column: number, clear = false): GridStackEngine {
1200 const copy: GridStackNode[] = [];
1201 nodes.forEach((n, i) => {
1202 // make sure we have an id in case this is new layout, else re-use id already set
1203 if (n._id === undefined) {
1204 const existing = n.id ? this.nodes.find(n2 => n2.id === n.id) : undefined; // find existing node using users id
1205 n._id = existing?._id ?? GridStackEngine._idSeq++;
1206 }
1207 copy[i] = {x: n.x, y: n.y, w: n.w, _id: n._id} // only thing we change is x,y,w and id to find it back
1208 });
1209 this._layouts = clear ? [] : this._layouts || []; // use array to find larger quick
1210 this._layouts[column] = copy;
1211 return this;
1212 }
1213
1214 /**
1215 * call to cache the given node layout internally to the given location so we can restore back when column changes size

Callers 2

columnChangedMethod · 0.95
loadMethod · 0.80

Calls 1

findMethod · 0.80

Tested by

no test coverage detected