Skip to content

Commit f50aa7f

Browse files
authored
Merge pull request #233 from swiety85/191-Possible-to-track-order-sequence-of-grid-items
feat(api): extend "change" event object to have isNew and oldValues
2 parents f78f5c8 + 4e5d541 commit f50aa7f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/gridList/gridList.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,26 +241,38 @@ export class GridList {
241241

242242
return this.items.map((item: GridListItem) => {
243243
const changes = [];
244+
const oldValues: {x?: number, y?: number, w?: number, h?: number} = {};
244245
const initItem = initialItems.find(initItm => initItm.$element === item.$element);
245246

246247
if (!initItem) {
247248
return {item, changes: ['x', 'y', 'w', 'h'], isNew: true};
248249
}
249250

250-
if (item.getValueX(breakpoint) !== initItem.getValueX(breakpoint)) {
251+
const oldX = initItem.getValueX(breakpoint);
252+
if (item.getValueX(breakpoint) !== oldX) {
251253
changes.push('x');
254+
if (oldX) {
255+
oldValues.x = oldX;
256+
}
252257
}
253-
if (item.getValueY(breakpoint) !== initItem.getValueY(breakpoint)) {
258+
259+
const oldY = initItem.getValueY(breakpoint);
260+
if (item.getValueY(breakpoint) !== oldY) {
254261
changes.push('y');
262+
if (oldY) {
263+
oldValues.y = oldY;
264+
}
255265
}
256266
if (item.w !== initItem.w) {
257267
changes.push('w');
268+
oldValues.w = initItem.w;
258269
}
259270
if (item.h !== initItem.h) {
260271
changes.push('h');
272+
oldValues.h = initItem.h;
261273
}
262274

263-
return {item, changes, isNew: false};
275+
return {item, oldValues, changes, isNew: false};
264276
})
265277
.filter((itemChange: { item: GridListItem, changes: Array<string> }) => {
266278
return itemChange.changes.length;

src/gridster.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ export class GridsterService {
576576
// should be called only once (not for each breakpoint)
577577
itemChange.item.itemComponent.change.emit({
578578
item: itemChange.item,
579+
oldValues: itemChange.oldValues || {},
580+
isNew: itemChange.isNew,
579581
changes: itemChange.changes,
580582
breakpoint: breakpoint
581583
});

0 commit comments

Comments
 (0)