@nemigo/svelte 2.10.2 → 2.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/tree.js +12 -31
  2. package/package.json +1 -1
package/dist/tree.js CHANGED
@@ -37,52 +37,33 @@ export class SvelteTree extends Emitter {
37
37
  },
38
38
  update: (record, mods) => {
39
39
  const item = this.map.get(record.id);
40
- const preview = { ...(item?.record.signal ?? record), ...mods };
41
- const prev_parent_id = record.parent_id;
42
- const mod_parent_id = mods.parent_id;
43
- const isParentChange = mod_parent_id !== undefined && mod_parent_id !== prev_parent_id;
44
- // --- элемент ещё не в поддереве ---
40
+ const current = item?.record.signal;
41
+ const preview = { ...(current ?? record), ...mods };
45
42
  if (!item) {
46
- // если после апдейта он попадает в наше поддерево — создаём
47
- if (this.__inScope(preview)) {
43
+ if (this.__inScope(preview))
48
44
  this.hooks.create(preview);
49
- }
50
45
  return;
51
46
  }
52
- // --- элемент уже в поддереве ---
53
- // если апдейт выталкивает его из поддерева (смена parent_id на "чужой") — удаляем
47
+ const prev_parent_id = current.parent_id;
48
+ const next_parent_id = preview.parent_id;
49
+ const isParentChange = prev_parent_id !== next_parent_id;
54
50
  if (isParentChange && !this.__inScope(preview)) {
55
51
  this.hooks.delete(record.id);
56
52
  return;
57
53
  }
58
- if (isDataEqual(record, preview))
54
+ if (!isParentChange && isDataEqual(current, preview))
59
55
  return;
60
56
  if (isParentChange) {
61
- this.dispatch("before-parent-update", {
62
- prev: prev_parent_id,
63
- item,
64
- preview,
65
- mods,
66
- });
67
- this.__parent(item, (items) => {
68
- this.__delete(items, item);
69
- });
57
+ this.dispatch("before-parent-update", { prev: prev_parent_id, item, preview, mods });
58
+ this.__parent(item, (items) => this.__delete(items, item));
70
59
  item.record.signal = preview;
71
- this.__parent(item, (items) => {
72
- this.__push(items, item);
73
- });
74
- this.dispatch("after-parent-update", {
75
- prev: prev_parent_id,
76
- item,
77
- mods,
78
- });
60
+ this.__parent(item, (items) => this.__push(items, item));
61
+ this.dispatch("after-parent-update", { prev: prev_parent_id, item, mods });
79
62
  }
80
63
  else {
81
64
  this.dispatch("before-update", item);
82
65
  item.record.signal = preview;
83
- this.__parent(item, (items) => {
84
- this.__sort(items);
85
- });
66
+ this.__parent(item, (items) => this.__sort(items));
86
67
  this.dispatch("after-update", item);
87
68
  }
88
69
  this.size.signal = this.map.size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/svelte",
3
- "version": "2.10.2",
3
+ "version": "2.10.3",
4
4
  "private": false,
5
5
  "license": "MPL-2.0",
6
6
  "author": {