@tschk/moonshine-dom 0.4.4 → 0.4.49
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/README.md +79 -10
- package/package.json +9 -4
- package/src/attributes.ts +38 -2
- package/src/binding.ts +65 -15
- package/src/component-instance.ts +3 -2
- package/src/component.ts +11 -0
- package/src/control.ts +121 -19
- package/src/dom.ts +24 -5
- package/src/framework-native.ts +18 -11
- package/src/head-ssr.ts +108 -0
- package/src/head.ts +34 -0
- package/src/platform.d.ts +4 -0
- package/src/platform.js +4 -0
- package/src/reactive.ts +22 -2
- package/src/resource-ssr.ts +73 -0
- package/src/resource.ts +7 -1
- package/src/ssr-attempt.ts +36 -1
- package/src/ssr-owner.ts +7 -0
- package/src/ssr.ts +403 -146
- package/src/store.ts +31 -0
package/src/store.ts
CHANGED
|
@@ -46,6 +46,37 @@ function raw<T>(value: T): T {
|
|
|
46
46
|
: value
|
|
47
47
|
) as T;
|
|
48
48
|
}
|
|
49
|
+
/** Return raw stores and unwrap embedded proxies; direct raw writes bypass tracking. */
|
|
50
|
+
export function unwrap<T>(value: T): T {
|
|
51
|
+
const initial = raw(value);
|
|
52
|
+
if (initial !== value || !wrappable(value)) return initial;
|
|
53
|
+
const seen = new WeakMap<object, unknown>();
|
|
54
|
+
function visit(item: unknown): unknown {
|
|
55
|
+
const target = raw(item);
|
|
56
|
+
if (target !== item || !wrappable(item)) return target;
|
|
57
|
+
if (seen.has(item)) return seen.get(item);
|
|
58
|
+
const result: Record<PropertyKey, any> = Object.isFrozen(item)
|
|
59
|
+
? Array.isArray(item)
|
|
60
|
+
? item.slice()
|
|
61
|
+
: { ...item }
|
|
62
|
+
: item;
|
|
63
|
+
seen.set(item, result);
|
|
64
|
+
const replace = (key: string | number) => {
|
|
65
|
+
const previous = result[key];
|
|
66
|
+
const next = visit(previous);
|
|
67
|
+
if (next !== previous) result[key] = next;
|
|
68
|
+
};
|
|
69
|
+
if (Array.isArray(result)) {
|
|
70
|
+
for (let index = 0; index < result.length; index++) replace(index);
|
|
71
|
+
} else {
|
|
72
|
+
for (const key of Object.keys(result))
|
|
73
|
+
if (!Object.getOwnPropertyDescriptor(result, key)?.get) replace(key);
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
return visit(value) as T;
|
|
78
|
+
}
|
|
79
|
+
|
|
49
80
|
function wrappable(value: unknown): value is Record<PropertyKey, any> {
|
|
50
81
|
if (value === null || typeof value !== "object") return false;
|
|
51
82
|
const prototype = Object.getPrototypeOf(value);
|