@torpor/view 0.4.8 → 0.4.9
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/watch/proxyGet.ts +4 -0
- package/test/watch-object/components/output/WatchUndefinedPropertyChange-client.ts +36 -0
- package/test/watch-object/components/output/WatchUndefinedPropertyChange-server.ts +18 -0
- package/test/watch-object/components/output/WatchUndefinedPropertyChange-types.ts +10 -0
- package/test/watch-object/components/temp/WatchUndefinedPropertyChange-client-210c8984d068fe46e681de4f63d744af34d75b7a.ts +36 -0
- package/test/watch-object/components/temp/WatchUndefinedPropertyChange-server-7af97c0938c3c851f60e86ef27188e0bcd432354.ts +18 -0
- package/test/watch-object/components/temp/WatchUndefinedPropertyChange-types-05e791b7c4023f8ae6e8dd548fe3f16ea8c16d10.ts +10 -0
- package/test/watch-object/watch-undefined-property-change.test.ts +51 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type ServerSlotRender from "../../../../src/types/ServerSlotRender";
|
|
2
|
+
import t_fmt from "../../../../src/render/formatText";
|
|
3
|
+
|
|
4
|
+
export default function Watched(
|
|
5
|
+
$props: Record<PropertyKey, any>,
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
$context?: Record<PropertyKey, any>,
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
$slots?: Record<string, ServerSlotRender>
|
|
10
|
+
): { body: string, head: string } {
|
|
11
|
+
let t_body = "";
|
|
12
|
+
let t_head = "";
|
|
13
|
+
|
|
14
|
+
/* User interface */
|
|
15
|
+
t_body += ` <p> ${t_fmt($props.text)} </p> `;
|
|
16
|
+
|
|
17
|
+
return { body: t_body, head: t_head };
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type SlotRender from "../../../../src/types/SlotRender";
|
|
2
|
+
|
|
3
|
+
declare function Watched(
|
|
4
|
+
$parent: ParentNode,
|
|
5
|
+
$anchor: Node | null,
|
|
6
|
+
$props?: Record<PropertyKey, any>,
|
|
7
|
+
$context?: Record<PropertyKey, any>,
|
|
8
|
+
$slots?: Record<string, SlotRender>,
|
|
9
|
+
): void;
|
|
10
|
+
export default Watched;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/vitest";
|
|
2
|
+
import { assert, expect, test } from "vitest";
|
|
3
|
+
import $watch from "../../src/watch/$watch";
|
|
4
|
+
import hydrateComponent from "../hydrateComponent";
|
|
5
|
+
import importComponent from "../importComponent";
|
|
6
|
+
import mountComponent from "../mountComponent";
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
text?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const source = `
|
|
13
|
+
export default function Watched() {
|
|
14
|
+
@render {
|
|
15
|
+
<p>
|
|
16
|
+
{$props.text}
|
|
17
|
+
</p>
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
test("watch undefined property change -- mounted", async () => {
|
|
23
|
+
let $state = $watch({});
|
|
24
|
+
|
|
25
|
+
const container = document.createElement("div");
|
|
26
|
+
const component = await importComponent(import.meta.filename, source, "client");
|
|
27
|
+
mountComponent(container, component, $state);
|
|
28
|
+
|
|
29
|
+
check(container, $state);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("watch undefined property change -- hydrated", async () => {
|
|
33
|
+
let $state = $watch({});
|
|
34
|
+
|
|
35
|
+
const container = document.createElement("div");
|
|
36
|
+
const clientComponent = await importComponent(import.meta.filename, source, "client");
|
|
37
|
+
const serverComponent = await importComponent(import.meta.filename, source, "server");
|
|
38
|
+
hydrateComponent(container, clientComponent, serverComponent, $state);
|
|
39
|
+
|
|
40
|
+
check(container, $state);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function check(container: HTMLElement, state: Props) {
|
|
44
|
+
assert(container.textContent);
|
|
45
|
+
|
|
46
|
+
expect(container.textContent.replace(/\s+/g, " ").trim()).toBe("");
|
|
47
|
+
|
|
48
|
+
state.text = "hello";
|
|
49
|
+
|
|
50
|
+
expect(container.textContent.replace(/\s+/g, " ").trim()).toBe("hello");
|
|
51
|
+
}
|