@ryupold/vode 0.12.1 → 0.12.3
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/package.json +1 -1
- package/src/vode.ts +27 -24
- package/vode.mjs +21 -22
package/package.json
CHANGED
package/src/vode.ts
CHANGED
|
@@ -104,7 +104,7 @@ export function createPatch<S extends object | unknown>(p: DeepPartial<S> | Effe
|
|
|
104
104
|
* - identity: `vode(["div", ["span", "bar"]])` => `["div", ["span", "bar"]]` --*rendered*-> `<div><span>bar</span></div>`
|
|
105
105
|
*/
|
|
106
106
|
export function vode<S extends object | unknown>(tag: Tag | Vode<S>, props?: Props<S> | ChildVode<S>, ...children: ChildVode<S>[]): Vode<S> {
|
|
107
|
-
if(!tag) throw new Error("tag must be a string or vode");
|
|
107
|
+
if (!tag) throw new Error("tag must be a string or vode");
|
|
108
108
|
if (Array.isArray(tag)) return tag;
|
|
109
109
|
else if (props) return [tag, props as Props<S>, ...children];
|
|
110
110
|
else return [tag, ...children];
|
|
@@ -289,10 +289,10 @@ export function mergeClass(a: ClassProp, b: ClassProp): ClassProp {
|
|
|
289
289
|
for (const item of a as string[]) {
|
|
290
290
|
aa[item] = true;
|
|
291
291
|
}
|
|
292
|
-
for (const bKey of (
|
|
292
|
+
for (const bKey of Object.keys(b)) {
|
|
293
293
|
aa[bKey] = (<Record<string, boolean | null | undefined>>b)[bKey];
|
|
294
294
|
}
|
|
295
|
-
return
|
|
295
|
+
return aa;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
throw new Error(`cannot merge classes of ${a} (${typeof a}) and ${b} (${typeof b})`);
|
|
@@ -564,31 +564,34 @@ function unwrap<S>(c: Component<S> | ChildVode<S>, s: S): ChildVode<S> {
|
|
|
564
564
|
|
|
565
565
|
function patchProperties<S>(patch: Dispatch<S>, node: ChildNode, oldProps?: Props<S>, newProps?: Props<S>, isSvg?: boolean) {
|
|
566
566
|
if (!newProps && !oldProps) return;
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
} else if (newProps) { // clear old props and set new in one loop
|
|
573
|
-
const combinedKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
574
|
-
for (const key of combinedKeys) {
|
|
567
|
+
|
|
568
|
+
// match existing properties
|
|
569
|
+
if (oldProps) {
|
|
570
|
+
for (const key in oldProps) {
|
|
575
571
|
const oldValue = oldProps[key as keyof Props<S>] as PropertyValue<S>;
|
|
576
|
-
const newValue = newProps[key as keyof Props<S>] as PropertyValue<S>;
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
(<any>node)["__" + key] = newValue;
|
|
572
|
+
const newValue = newProps?.[key as keyof Props<S>] as PropertyValue<S>;
|
|
573
|
+
|
|
574
|
+
if (oldValue !== newValue) {
|
|
575
|
+
if (newProps) newProps[key as keyof Props<S>] = patchProperty(patch, node, key, oldValue, newValue, isSvg);
|
|
576
|
+
else patchProperty(patch, node, key, oldValue, undefined, isSvg);
|
|
583
577
|
}
|
|
584
|
-
|
|
585
|
-
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
//new properties that weren't in oldProps
|
|
582
|
+
if (newProps && oldProps) {
|
|
583
|
+
for (const key in newProps) {
|
|
584
|
+
if (!(key in oldProps)) {
|
|
585
|
+
const newValue = newProps[key as keyof Props<S>] as PropertyValue<S>;
|
|
586
|
+
newProps[key as keyof Props<S>] = patchProperty(patch, <Element>node, key, undefined, newValue, isSvg);
|
|
586
587
|
}
|
|
587
588
|
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
589
|
+
}
|
|
590
|
+
// only new props
|
|
591
|
+
else if (newProps) {
|
|
592
|
+
for (const key in newProps) {
|
|
593
|
+
const newValue = newProps[key as keyof Props<S>] as PropertyValue<S>;
|
|
594
|
+
newProps[key as keyof Props<S>] = patchProperty(patch, <Element>node, key, undefined, newValue, isSvg);
|
|
592
595
|
}
|
|
593
596
|
}
|
|
594
597
|
}
|
package/vode.mjs
CHANGED
|
@@ -164,10 +164,10 @@ function mergeClass(a, b) {
|
|
|
164
164
|
for (const item of a) {
|
|
165
165
|
aa[item] = true;
|
|
166
166
|
}
|
|
167
|
-
for (const bKey of
|
|
167
|
+
for (const bKey of Object.keys(b)) {
|
|
168
168
|
aa[bKey] = b[bKey];
|
|
169
169
|
}
|
|
170
|
-
return
|
|
170
|
+
return aa;
|
|
171
171
|
}
|
|
172
172
|
throw new Error(`cannot merge classes of ${a} (${typeof a}) and ${b} (${typeof b})`);
|
|
173
173
|
}
|
|
@@ -390,30 +390,29 @@ function unwrap(c, s) {
|
|
|
390
390
|
function patchProperties(patch, node, oldProps, newProps, isSvg) {
|
|
391
391
|
if (!newProps && !oldProps)
|
|
392
392
|
return;
|
|
393
|
-
if (
|
|
394
|
-
for (const key in
|
|
395
|
-
const newValue = newProps[key];
|
|
396
|
-
newProps[key] = patchProperty(patch, node, key, undefined, newValue, isSvg);
|
|
397
|
-
}
|
|
398
|
-
} else if (newProps) {
|
|
399
|
-
const combinedKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
400
|
-
for (const key of combinedKeys) {
|
|
393
|
+
if (oldProps) {
|
|
394
|
+
for (const key in oldProps) {
|
|
401
395
|
const oldValue = oldProps[key];
|
|
402
|
-
const newValue = newProps[key];
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
if (oldEvent && oldEvent !== newValue || !oldEvent && oldValue !== newValue) {
|
|
396
|
+
const newValue = newProps?.[key];
|
|
397
|
+
if (oldValue !== newValue) {
|
|
398
|
+
if (newProps)
|
|
406
399
|
newProps[key] = patchProperty(patch, node, key, oldValue, newValue, isSvg);
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
} else if (oldValue !== newValue) {
|
|
410
|
-
newProps[key] = patchProperty(patch, node, key, oldValue, newValue, isSvg);
|
|
400
|
+
else
|
|
401
|
+
patchProperty(patch, node, key, oldValue, undefined, isSvg);
|
|
411
402
|
}
|
|
412
403
|
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
404
|
+
}
|
|
405
|
+
if (newProps && oldProps) {
|
|
406
|
+
for (const key in newProps) {
|
|
407
|
+
if (!(key in oldProps)) {
|
|
408
|
+
const newValue = newProps[key];
|
|
409
|
+
newProps[key] = patchProperty(patch, node, key, undefined, newValue, isSvg);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} else if (newProps) {
|
|
413
|
+
for (const key in newProps) {
|
|
414
|
+
const newValue = newProps[key];
|
|
415
|
+
newProps[key] = patchProperty(patch, node, key, undefined, newValue, isSvg);
|
|
417
416
|
}
|
|
418
417
|
}
|
|
419
418
|
}
|