Skip to content

Commit 252d5b8

Browse files
authored
Feature/clear (#52)
* Clear values in domdom when old value is array or object * Fix lints
1 parent ed75d55 commit 252d5b8

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/godmode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export class GodMode<T> {
6868
private _set = (path: string[], value: any) => {
6969
value = deregulate(value);
7070
const p = path.join('.');
71-
if (Array.isArray(this.domdom.get(p))) {
72-
this.domdom.set(p, []);
71+
const oldValue = this.domdom.get(p);
72+
if (Array.isArray(oldValue) || isProbablyPlainObject(oldValue)) {
73+
this.domdom.set(p, undefined);
7374
}
7475
this.domdom.set(p, value);
7576
};

test/index.test.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ test.skip('Listener in when 2', async t => {
634634
test('Mounted', async t => {
635635
t.plan(1);
636636

637-
const Hello = ({}, { mounted }: Opts) => {
637+
const Hello = (_, { mounted }: Opts) => {
638638
mounted(() => t.pass());
639639
return <div />;
640640
};
@@ -652,7 +652,7 @@ test('Mounted', async t => {
652652
test('Mounted on/off', async t => {
653653
t.plan(2);
654654

655-
const Hello = ({}, { mounted }: Opts) => {
655+
const Hello = (_, { mounted }: Opts) => {
656656
mounted(() => t.pass());
657657
return <div />;
658658
};
@@ -762,7 +762,7 @@ test('Update array without element', async t => {
762762
});
763763

764764
test('Containment', async t => {
765-
const Button = ({}, { children }: Opts) => <button>{children}</button>;
765+
const Button = (_, { children }: Opts) => <button>{children}</button>;
766766

767767
init(element, <Button>Test</Button>);
768768
t.is(await html(), '<button>Test</button>');
@@ -1108,6 +1108,7 @@ test('When + change', async t => {
11081108
case true:
11091109
return <p>{don('ok')}</p>;
11101110
}
1111+
return null;
11111112
})}
11121113
</div>
11131114
);
@@ -1127,6 +1128,7 @@ test('When + change 2', async t => {
11271128
case true:
11281129
return <p>{don('ok')}</p>;
11291130
}
1131+
return null;
11301132
})}
11311133
</div>
11321134
);
@@ -1156,6 +1158,7 @@ test('When + filterOn 2', async t => {
11561158
</div>
11571159
);
11581160
}
1161+
return null;
11591162
})}
11601163
</div>
11611164
);
@@ -1190,6 +1193,7 @@ test('When + filterOn', async t => {
11901193
</div>
11911194
);
11921195
}
1196+
return null;
11931197
})}
11941198
</div>
11951199
);
@@ -1285,6 +1289,7 @@ test('filterOn mounted destroy mounted', async t => {
12851289
</div>
12861290
);
12871291
}
1292+
return null;
12881293
})}
12891294
</div>
12901295
);
@@ -1323,6 +1328,7 @@ test('When + filterOn const element', async t => {
13231328
</div>
13241329
);
13251330
}
1331+
return null;
13261332
})}
13271333
</div>
13281334
);
@@ -1340,7 +1346,7 @@ test('When + filterOn const element', async t => {
13401346
test('When + filterOn const text', async t => {
13411347
const view = (
13421348
<div>
1343-
{don('show').map(t => {
1349+
{don('show').map((t): any => {
13441350
switch (t) {
13451351
case true:
13461352
return (
@@ -1354,6 +1360,7 @@ test('When + filterOn const text', async t => {
13541360
</div>
13551361
);
13561362
}
1363+
return null;
13571364
})}
13581365
</div>
13591366
);
@@ -1478,6 +1485,7 @@ test('When and on no duplicated', async t => {
14781485
case 'ready':
14791486
return <Yes />;
14801487
}
1488+
return null;
14811489
})}
14821490
</div>
14831491
);
@@ -1527,6 +1535,7 @@ test('When + pathifier', async t => {
15271535
</div>
15281536
);
15291537
}
1538+
return null;
15301539
})}
15311540
</div>
15321541
);
@@ -1894,6 +1903,7 @@ test('TS and types', async t => {
18941903
<div>
18951904
{don('ok').map<Ok>(ok => {
18961905
t.is(ok.name, 'Hello');
1906+
return null;
18971907
})}
18981908
</div>
18991909
);
@@ -2031,7 +2041,7 @@ test('Pathifier instead of Domponent', async t => {
20312041
});
20322042

20332043
test('Pathifier instead of Domponent with mounted', async t => {
2034-
function Ok({}, { mounted }) {
2044+
function Ok(_, { mounted }) {
20352045
mounted(() => {
20362046
t.pass();
20372047
});
@@ -2090,12 +2100,15 @@ test('xmlns', async t => {
20902100
init(
20912101
element,
20922102
<div>
2093-
<a xmlns="http://eh/eh">
2103+
<a xmlns="http://eh/eh" href="eh">
20942104
<b>eh</b>
20952105
</a>
20962106
</div>
20972107
);
2098-
t.is(await html(), '<div><a xmlns="http://eh/eh"><b>eh</b></a></div>');
2108+
t.is(
2109+
await html(),
2110+
'<div><a xmlns="http://eh/eh" href="eh"><b>eh</b></a></div>'
2111+
);
20992112
t.is(document.querySelector('a')?.namespaceURI, 'http://eh/eh');
21002113
t.is(document.querySelector('b')?.namespaceURI, 'http://eh/eh');
21012114
});

0 commit comments

Comments
 (0)