Skip to content

Commit acb8ba8

Browse files
committed
0.2.3: Fix the bug to set the right length value after vanX.replace call to an array
1 parent 96b00d9 commit acb8ba8

File tree

7 files changed

+18
-2
lines changed

7 files changed

+18
-2
lines changed

x/dist/van-x.nomodule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
}
100100
for (let k in obj) delete obj[k]
101101
for (let k in newObj) obj[k] = newObj[k]
102+
if (Array.isArray(obj)) while (obj.length > 0 && !(obj.length - 1 in obj)) --obj.length
102103
items[statesSym] = newStates
103104
++items[keysGenSym].val
104105
}

x/dist/van-x.nomodule.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vanjs-ext",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "The official extension library for VanJS",
55
"files": [
66
"src/van-x.js",

x/src/van-x.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ let replace = (items, f) => {
115115

116116
for (let k in obj) delete obj[k]
117117
for (let k in newObj) obj[k] = newObj[k]
118+
if (Array.isArray(obj)) while (obj.length > 0 && !(obj.length - 1 in obj)) --obj.length
118119
items[statesSym] = newStates
119120
++items[keysGenSym].val
120121
}

x/test/van-x.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ window.runTests = async (van, vanX, file) => {
164164
assertEq(json.val, '[3,null,4]');
165165
vanX.replace(data, _ => [1, 2, 3, 4]);
166166
assertEq(json.val, '[1,2,3,4]');
167+
vanX.replace(data, _ => [1, 2]);
168+
assertEq(json.val, '[1,2]');
169+
vanX.replace(data, _ => []);
170+
assertEq(json.val, '[]');
167171
},
168172
reactive_objJson: () => {
169173
const data = vanX.reactive({ a: 1, b: 2 });

x/test/van-x.test.nomodule.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ window.runTests = async (van, vanX, file) => {
164164
assertEq(json.val, '[3,null,4]');
165165
vanX.replace(data, _ => [1, 2, 3, 4]);
166166
assertEq(json.val, '[1,2,3,4]');
167+
vanX.replace(data, _ => [1, 2]);
168+
assertEq(json.val, '[1,2]');
169+
vanX.replace(data, _ => []);
170+
assertEq(json.val, '[]');
167171
},
168172
reactive_objJson: () => {
169173
const data = vanX.reactive({ a: 1, b: 2 });

x/test/van-x.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ window.runTests = async (van: Van, vanX: typeof vanXObj, file: string) => {
219219

220220
vanX.replace(data, _ => [1, 2, 3, 4])
221221
assertEq(json.val, '[1,2,3,4]')
222+
223+
vanX.replace(data, _ => [1, 2])
224+
assertEq(json.val, '[1,2]')
225+
226+
vanX.replace(data, _ => [])
227+
assertEq(json.val, '[]')
222228
},
223229

224230
reactive_objJson: () => {

0 commit comments

Comments
 (0)