mol_wire_dom 0.0.1406 → 0.0.1408
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.
- package/node.d.ts +5 -0
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +26 -11
- package/node.js.map +1 -1
- package/node.mjs +26 -11
- package/node.test.js +115 -36
- package/node.test.js.map +1 -1
- package/package.json +2 -1
package/node.mjs
CHANGED
@@ -1221,6 +1221,16 @@ var $;
|
|
1221
1221
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
1222
1222
|
})($ || ($ = {}));
|
1223
1223
|
|
1224
|
+
;
|
1225
|
+
"use strict";
|
1226
|
+
var $;
|
1227
|
+
(function ($) {
|
1228
|
+
function $mol_maybe(value) {
|
1229
|
+
return (value == null) ? [] : [value];
|
1230
|
+
}
|
1231
|
+
$.$mol_maybe = $mol_maybe;
|
1232
|
+
})($ || ($ = {}));
|
1233
|
+
|
1224
1234
|
;
|
1225
1235
|
"use strict";
|
1226
1236
|
var $;
|
@@ -1288,33 +1298,38 @@ var $;
|
|
1288
1298
|
return $$.$mol_tree2_to_string(this);
|
1289
1299
|
}
|
1290
1300
|
insert(value, ...path) {
|
1301
|
+
return this.update($mol_maybe(value), ...path)[0];
|
1302
|
+
}
|
1303
|
+
update(value, ...path) {
|
1291
1304
|
if (path.length === 0)
|
1292
1305
|
return value;
|
1293
1306
|
const type = path[0];
|
1294
1307
|
if (typeof type === 'string') {
|
1295
1308
|
let replaced = false;
|
1296
|
-
const sub = this.kids.
|
1309
|
+
const sub = this.kids.flatMap((item, index) => {
|
1297
1310
|
if (item.type !== type)
|
1298
1311
|
return item;
|
1299
1312
|
replaced = true;
|
1300
|
-
return item.
|
1313
|
+
return item.update(value, ...path.slice(1));
|
1301
1314
|
}).filter(Boolean);
|
1302
1315
|
if (!replaced && value) {
|
1303
|
-
sub.push(this.struct(type, []).
|
1316
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
1304
1317
|
}
|
1305
|
-
return this.clone(sub);
|
1318
|
+
return [this.clone(sub)];
|
1306
1319
|
}
|
1307
1320
|
else if (typeof type === 'number') {
|
1308
|
-
const
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1321
|
+
const ins = (this.kids[type] || this.list([]))
|
1322
|
+
.update(value, ...path.slice(1));
|
1323
|
+
return [this.clone([
|
1324
|
+
...this.kids.slice(0, type),
|
1325
|
+
...ins,
|
1326
|
+
...this.kids.slice(type + 1),
|
1327
|
+
])];
|
1312
1328
|
}
|
1313
1329
|
else {
|
1314
1330
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
1315
|
-
.
|
1316
|
-
|
1317
|
-
return this.clone(kids);
|
1331
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
1332
|
+
return [this.clone(kids)];
|
1318
1333
|
}
|
1319
1334
|
}
|
1320
1335
|
select(...path) {
|
package/node.test.js
CHANGED
@@ -1212,6 +1212,16 @@ var $;
|
|
1212
1212
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
1213
1213
|
})($ || ($ = {}));
|
1214
1214
|
|
1215
|
+
;
|
1216
|
+
"use strict";
|
1217
|
+
var $;
|
1218
|
+
(function ($) {
|
1219
|
+
function $mol_maybe(value) {
|
1220
|
+
return (value == null) ? [] : [value];
|
1221
|
+
}
|
1222
|
+
$.$mol_maybe = $mol_maybe;
|
1223
|
+
})($ || ($ = {}));
|
1224
|
+
|
1215
1225
|
;
|
1216
1226
|
"use strict";
|
1217
1227
|
var $;
|
@@ -1279,33 +1289,38 @@ var $;
|
|
1279
1289
|
return $$.$mol_tree2_to_string(this);
|
1280
1290
|
}
|
1281
1291
|
insert(value, ...path) {
|
1292
|
+
return this.update($mol_maybe(value), ...path)[0];
|
1293
|
+
}
|
1294
|
+
update(value, ...path) {
|
1282
1295
|
if (path.length === 0)
|
1283
1296
|
return value;
|
1284
1297
|
const type = path[0];
|
1285
1298
|
if (typeof type === 'string') {
|
1286
1299
|
let replaced = false;
|
1287
|
-
const sub = this.kids.
|
1300
|
+
const sub = this.kids.flatMap((item, index) => {
|
1288
1301
|
if (item.type !== type)
|
1289
1302
|
return item;
|
1290
1303
|
replaced = true;
|
1291
|
-
return item.
|
1304
|
+
return item.update(value, ...path.slice(1));
|
1292
1305
|
}).filter(Boolean);
|
1293
1306
|
if (!replaced && value) {
|
1294
|
-
sub.push(this.struct(type, []).
|
1307
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
1295
1308
|
}
|
1296
|
-
return this.clone(sub);
|
1309
|
+
return [this.clone(sub)];
|
1297
1310
|
}
|
1298
1311
|
else if (typeof type === 'number') {
|
1299
|
-
const
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1312
|
+
const ins = (this.kids[type] || this.list([]))
|
1313
|
+
.update(value, ...path.slice(1));
|
1314
|
+
return [this.clone([
|
1315
|
+
...this.kids.slice(0, type),
|
1316
|
+
...ins,
|
1317
|
+
...this.kids.slice(type + 1),
|
1318
|
+
])];
|
1303
1319
|
}
|
1304
1320
|
else {
|
1305
1321
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
1306
|
-
.
|
1307
|
-
|
1308
|
-
return this.clone(kids);
|
1322
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
1323
|
+
return [this.clone(kids)];
|
1309
1324
|
}
|
1310
1325
|
}
|
1311
1326
|
select(...path) {
|
@@ -3640,41 +3655,105 @@ var $;
|
|
3640
3655
|
});
|
3641
3656
|
})($ || ($ = {}));
|
3642
3657
|
|
3658
|
+
;
|
3659
|
+
"use strict";
|
3660
|
+
var $;
|
3661
|
+
(function ($) {
|
3662
|
+
$mol_test({
|
3663
|
+
'all cases of using maybe'() {
|
3664
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
3665
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
3666
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
3667
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
3668
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
3669
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
3670
|
+
},
|
3671
|
+
});
|
3672
|
+
})($ || ($ = {}));
|
3673
|
+
|
3643
3674
|
;
|
3644
3675
|
"use strict";
|
3645
3676
|
var $;
|
3646
3677
|
(function ($_1) {
|
3678
|
+
function check(tree, ideal) {
|
3679
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
3680
|
+
}
|
3647
3681
|
$mol_test({
|
3648
3682
|
'inserting'($) {
|
3649
|
-
|
3650
|
-
|
3651
|
-
|
3652
|
-
|
3653
|
-
|
3654
|
-
|
3655
|
-
|
3656
|
-
|
3657
|
-
|
3658
|
-
|
3659
|
-
|
3660
|
-
|
3661
|
-
|
3662
|
-
.insert($mol_tree2.struct('x'),
|
3663
|
-
|
3664
|
-
|
3665
|
-
|
3666
|
-
|
3683
|
+
check($.$mol_tree2_from_string(`
|
3684
|
+
a b c d
|
3685
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
3686
|
+
a b x
|
3687
|
+
`);
|
3688
|
+
check($.$mol_tree2_from_string(`
|
3689
|
+
a b
|
3690
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
3691
|
+
a b c x
|
3692
|
+
`);
|
3693
|
+
check($.$mol_tree2_from_string(`
|
3694
|
+
a b c d
|
3695
|
+
`)
|
3696
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
3697
|
+
a b x
|
3698
|
+
`);
|
3699
|
+
check($.$mol_tree2_from_string(`
|
3700
|
+
a b
|
3701
|
+
`)
|
3702
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
3703
|
+
a b \\
|
3704
|
+
x
|
3705
|
+
`);
|
3706
|
+
check($.$mol_tree2_from_string(`
|
3707
|
+
a b c d
|
3708
|
+
`)
|
3709
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
3710
|
+
a b x
|
3711
|
+
`);
|
3712
|
+
check($.$mol_tree2_from_string(`
|
3713
|
+
a b
|
3714
|
+
`)
|
3715
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
3716
|
+
a b \\
|
3717
|
+
x
|
3718
|
+
`);
|
3719
|
+
},
|
3720
|
+
'updating'($) {
|
3721
|
+
check($.$mol_tree2_from_string(`
|
3722
|
+
a b c d
|
3723
|
+
`).update([], 'a', 'b', 'c')[0], `
|
3724
|
+
a b
|
3725
|
+
`);
|
3726
|
+
check($.$mol_tree2_from_string(`
|
3727
|
+
a b c d
|
3728
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
3729
|
+
x
|
3730
|
+
`);
|
3731
|
+
check($.$mol_tree2_from_string(`
|
3732
|
+
a b c d
|
3733
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
3734
|
+
a b
|
3735
|
+
x
|
3736
|
+
y
|
3737
|
+
`);
|
3667
3738
|
},
|
3668
3739
|
'deleting'($) {
|
3669
|
-
|
3670
|
-
|
3671
|
-
|
3672
|
-
|
3673
|
-
|
3674
|
-
|
3740
|
+
const base = $.$mol_tree2_from_string(`
|
3741
|
+
a b c d
|
3742
|
+
`);
|
3743
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
3744
|
+
a b
|
3745
|
+
`);
|
3746
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
3747
|
+
a b d
|
3748
|
+
`);
|
3749
|
+
check(base.insert(null, 0, 0, 0), `
|
3750
|
+
a b
|
3751
|
+
`);
|
3675
3752
|
},
|
3676
3753
|
'hack'($) {
|
3677
|
-
const res = $.$mol_tree2_from_string(`
|
3754
|
+
const res = $.$mol_tree2_from_string(`
|
3755
|
+
foo bar xxx
|
3756
|
+
`)
|
3678
3757
|
.hack({
|
3679
3758
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
3680
3759
|
});
|