ks-fwork 2.0.1 → 3.0.1

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.
@@ -40,81 +40,51 @@ class ArrayWithOriginalIndices {
40
40
  return this.#originalIndices[index];
41
41
  }
42
42
 
43
- // REMOVE
44
- isRemoval(index, newArray) {
45
- // Bail out if index is past the end of the old array.
46
- if (index >= this.length) { return false; }
47
-
48
- const item = this.#oldArray[index];
49
- const indexInNewArray = newArray.findIndex((newArrayItem) => this.#equalsFn(item, newArrayItem))
50
-
51
- return indexInNewArray === -1;
43
+ // ADD
44
+ isAddition(item, startIndex) {
45
+ return this.findIndexFrom(item, startIndex) === -1;
52
46
  }
53
47
 
54
- removeItem(index) {
48
+ addItem(item, index) {
55
49
  const operation = {
56
- op: ARRAY_DIFF_OP.REMOVE,
50
+ op: ARRAY_DIFF_OP.ADD,
57
51
  index,
58
- item: this.#oldArray[index],
52
+ item
59
53
  }
60
54
 
61
- this.#oldArray.splice(index, 1);
62
- this.#originalIndices.splice(index, 1);
55
+ this.#oldArray.splice(index, 0, item);
56
+ this.#originalIndices.splice(index, 0, -1);
63
57
 
64
58
  return operation;
65
59
  }
66
60
 
67
- // NOOP
68
- isNoop(index, newArray) {
61
+ // REMOVE
62
+ isRemoval(index, newArray) {
69
63
  // Bail out if index is past the end of the old array.
70
- if (index >= this.length) {return false; }
64
+ if (index >= this.length) { return false; }
71
65
 
72
66
  const item = this.#oldArray[index];
73
- const newArrayItem = newArray[index];
74
-
75
- return this.#equalsFn(item, newArrayItem);
76
- }
77
-
78
- noopItem(index) {
79
- return {
80
- op: ARRAY_DIFF_OP.NOOP,
81
- originalIndex: this.originalIndexAt(index),
82
- index,
83
- item: this.#oldArray[index],
84
- }
85
- }
86
-
87
- // ADD
88
- isAddition(item, fromIndex) {
89
- return this.findFromIndex(item, fromIndex) === -1;
90
- }
91
-
92
- findFromIndex(item, fromIndex) {
93
- for (let i = fromIndex; i < this.length; i++) {
94
- if (this.#equalsFn(item, this.#oldArray[i])) {
95
- return i;
96
- }
97
- }
67
+ const indexInNewArray = newArray.findIndex((newArrayItem) => this.#equalsFn(item, newArrayItem))
98
68
 
99
- return -1;
69
+ return indexInNewArray === -1;
100
70
  }
101
71
 
102
- addItem(item, index) {
72
+ removeItem(index) {
103
73
  const operation = {
104
- op: ARRAY_DIFF_OP.ADD,
74
+ op: ARRAY_DIFF_OP.REMOVE,
105
75
  index,
106
- item
76
+ item: this.#oldArray[index],
107
77
  }
108
78
 
109
- this.#oldArray.splice(index, 0, item);
110
- this.#originalIndices.splice(index, 0, -1);
79
+ this.#oldArray.splice(index, 1);
80
+ this.#originalIndices.splice(index, 1);
111
81
 
112
82
  return operation;
113
83
  }
114
84
 
115
85
  // MOVE
116
86
  moveItem(item, toIndex) {
117
- const fromIndex = this.findFromIndex(item, toIndex);
87
+ const fromIndex = this.findIndexFrom(item, toIndex);
118
88
 
119
89
  const operation = {
120
90
  op: ARRAY_DIFF_OP.MOVE,
@@ -133,7 +103,27 @@ class ArrayWithOriginalIndices {
133
103
  return operation;
134
104
  }
135
105
 
136
- // REMOVE ITEMS AFTER
106
+ // NOOP
107
+ isNoop(index, newArray) {
108
+ // Bail out if index is past the end of the old array.
109
+ if (index >= this.length) {return false; }
110
+
111
+ const item = this.#oldArray[index];
112
+ const newArrayItem = newArray[index];
113
+
114
+ return this.#equalsFn(item, newArrayItem);
115
+ }
116
+
117
+ noopItem(index) {
118
+ return {
119
+ op: ARRAY_DIFF_OP.NOOP,
120
+ originalIndex: this.originalIndexAt(index),
121
+ index,
122
+ item: this.#oldArray[index],
123
+ }
124
+ }
125
+
126
+ // Remove all items after specified index
137
127
  removeItemsAfter(index) {
138
128
  const operations = [];
139
129
 
@@ -143,6 +133,17 @@ class ArrayWithOriginalIndices {
143
133
 
144
134
  return operations;
145
135
  }
136
+
137
+ // Return the first index at or after startIndex where the item matches, or -1 if item is not found.
138
+ findIndexFrom(item, startIndex) {
139
+ for (let i = startIndex; i < this.length; i++) {
140
+ if (this.#equalsFn(item, this.#oldArray[i])) {
141
+ return i;
142
+ }
143
+ }
144
+
145
+ return -1;
146
+ }
146
147
  }
147
148
 
148
149
  export function arraysDiffSequence(oldArray, newArray, equalsFn = (a, b) => a === b) {
@@ -9,4 +9,8 @@ export function objectsDiff(oldObj, newObj) {
9
9
  (key) => key in oldObj && oldObj[key] !== newObj[key]
10
10
  ),
11
11
  }
12
+ }
13
+
14
+ export function hasOwnProperty(obj, prop) {
15
+ return Object.prototype.hasOwnProperty.call(obj, prop);
12
16
  }
@@ -0,0 +1,6 @@
1
+ export function extractPropsAndEvents(vNode) {
2
+ const { on: events = {}, ...props } = vNode.props;
3
+ delete props.key;
4
+
5
+ return { props, events }
6
+ }