@praxisjs/decorators 0.2.0 → 0.3.0
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 +19 -0
- package/dist/component/component.d.ts +2 -2
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/component.js +5 -2
- package/dist/component/component.js.map +1 -1
- package/dist/component/index.d.ts +0 -1
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/index.js +0 -1
- package/dist/component/index.js.map +1 -1
- package/dist/component/lazy.d.ts +2 -2
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +8 -8
- package/dist/component/lazy.js.map +1 -1
- package/dist/component/virtual.d.ts +2 -2
- package/dist/component/virtual.d.ts.map +1 -1
- package/dist/component/virtual.js +45 -14
- package/dist/component/virtual.js.map +1 -1
- package/dist/events/emit.d.ts +2 -1
- package/dist/events/emit.d.ts.map +1 -1
- package/dist/events/emit.js +11 -16
- package/dist/events/emit.js.map +1 -1
- package/dist/events/helper.d.ts +2 -2
- package/dist/events/helper.d.ts.map +1 -1
- package/dist/events/helper.js.map +1 -1
- package/dist/events/on-command.d.ts +2 -1
- package/dist/events/on-command.d.ts.map +1 -1
- package/dist/events/on-command.js +30 -27
- package/dist/events/on-command.js.map +1 -1
- package/dist/functions/bind.d.ts +2 -1
- package/dist/functions/bind.d.ts.map +1 -1
- package/dist/functions/bind.js +10 -15
- package/dist/functions/bind.js.map +1 -1
- package/dist/functions/debounce.d.ts +2 -1
- package/dist/functions/debounce.d.ts.map +1 -1
- package/dist/functions/debounce.js +20 -24
- package/dist/functions/debounce.js.map +1 -1
- package/dist/functions/log.d.ts +2 -1
- package/dist/functions/log.d.ts.map +1 -1
- package/dist/functions/log.js +5 -6
- package/dist/functions/log.js.map +1 -1
- package/dist/functions/memo.d.ts +2 -1
- package/dist/functions/memo.d.ts.map +1 -1
- package/dist/functions/memo.js +5 -6
- package/dist/functions/memo.js.map +1 -1
- package/dist/functions/once.d.ts +2 -1
- package/dist/functions/once.d.ts.map +1 -1
- package/dist/functions/once.js +3 -5
- package/dist/functions/once.js.map +1 -1
- package/dist/functions/retry.d.ts +2 -1
- package/dist/functions/retry.d.ts.map +1 -1
- package/dist/functions/retry.js +3 -5
- package/dist/functions/retry.js.map +1 -1
- package/dist/functions/throttle.d.ts +2 -1
- package/dist/functions/throttle.d.ts.map +1 -1
- package/dist/functions/throttle.js +18 -22
- package/dist/functions/throttle.js.map +1 -1
- package/dist/functions/watch.d.ts +7 -7
- package/dist/functions/watch.d.ts.map +1 -1
- package/dist/functions/watch.js +31 -35
- package/dist/functions/watch.js.map +1 -1
- package/dist/functions/when.d.ts +2 -1
- package/dist/functions/when.d.ts.map +1 -1
- package/dist/functions/when.js +24 -24
- package/dist/functions/when.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/properties/history.d.ts +3 -2
- package/dist/properties/history.d.ts.map +1 -1
- package/dist/properties/history.js +35 -27
- package/dist/properties/history.js.map +1 -1
- package/dist/properties/persisted.d.ts +3 -2
- package/dist/properties/persisted.d.ts.map +1 -1
- package/dist/properties/persisted.js +20 -23
- package/dist/properties/persisted.js.map +1 -1
- package/dist/properties/prop.d.ts +2 -1
- package/dist/properties/prop.d.ts.map +1 -1
- package/dist/properties/prop.js +24 -13
- package/dist/properties/prop.js.map +1 -1
- package/dist/properties/slot.d.ts +4 -8
- package/dist/properties/slot.d.ts.map +1 -1
- package/dist/properties/slot.js +34 -24
- package/dist/properties/slot.js.map +1 -1
- package/dist/properties/state.d.ts +2 -1
- package/dist/properties/state.d.ts.map +1 -1
- package/dist/properties/state.js +19 -19
- package/dist/properties/state.js.map +1 -1
- package/package.json +3 -4
- package/src/component/component.ts +9 -2
- package/src/component/index.ts +0 -1
- package/src/component/lazy.ts +10 -8
- package/src/component/virtual.tsx +71 -28
- package/src/events/emit.ts +15 -22
- package/src/events/helper.ts +5 -2
- package/src/events/on-command.ts +43 -44
- package/src/functions/bind.ts +14 -18
- package/src/functions/debounce.ts +23 -26
- package/src/functions/log.ts +11 -11
- package/src/functions/memo.ts +8 -9
- package/src/functions/once.ts +7 -10
- package/src/functions/retry.ts +7 -12
- package/src/functions/throttle.ts +21 -24
- package/src/functions/watch.ts +44 -48
- package/src/functions/when.ts +30 -32
- package/src/index.ts +10 -2
- package/src/properties/history.ts +49 -32
- package/src/properties/persisted.ts +40 -31
- package/src/properties/prop.ts +30 -13
- package/src/properties/slot.ts +46 -50
- package/src/properties/state.ts +24 -18
- package/dist/component/lifecycle.d.ts +0 -3
- package/dist/component/lifecycle.d.ts.map +0 -1
- package/dist/component/lifecycle.js +0 -35
- package/dist/component/lifecycle.js.map +0 -1
- package/dist/component/memoize.d.ts +0 -5
- package/dist/component/memoize.d.ts.map +0 -1
- package/dist/component/memoize.js +0 -23
- package/dist/component/memoize.js.map +0 -1
- package/src/component/lifecycle.ts +0 -47
- package/src/component/memoize.ts +0 -31
|
@@ -1,40 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
import { type HistoryElement, history } from "@praxisjs/core/internal";
|
|
3
|
+
import type { Signal } from "@praxisjs/shared";
|
|
2
4
|
|
|
3
|
-
export type WithHistory<T, K extends keyof T> = Record
|
|
5
|
+
export type WithHistory<T, K extends keyof T> = Record<
|
|
6
|
+
`${string & K}History`,
|
|
7
|
+
HistoryElement<T[K]>
|
|
8
|
+
>;
|
|
4
9
|
|
|
5
10
|
export function History(limit = 50) {
|
|
6
|
-
return function (
|
|
7
|
-
|
|
11
|
+
return function (
|
|
12
|
+
_value: undefined,
|
|
13
|
+
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
14
|
+
): void {
|
|
8
15
|
const histories = new WeakMap<object, HistoryElement<unknown>>();
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
context.addInitializer(function (this: unknown) {
|
|
18
|
+
const instance = this as Record<string, unknown>;
|
|
19
|
+
const propertyKey = context.name as string;
|
|
20
|
+
const historyKey = `${propertyKey}History`;
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(instance, historyKey, {
|
|
23
|
+
get(this: Record<string, unknown>): HistoryElement<unknown> {
|
|
24
|
+
if (!histories.has(this)) {
|
|
25
|
+
const source = () => this[propertyKey];
|
|
26
|
+
|
|
27
|
+
const h = history(source as Signal<unknown>, limit);
|
|
28
|
+
|
|
29
|
+
const originalUndo = () => {
|
|
30
|
+
h.undo();
|
|
31
|
+
};
|
|
32
|
+
const originalRedo = () => {
|
|
33
|
+
h.redo();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
h.undo = () => {
|
|
37
|
+
const prev = h.values()[h.values().length - 2];
|
|
38
|
+
if (prev === undefined) return;
|
|
39
|
+
originalUndo();
|
|
40
|
+
this[propertyKey] = prev;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
h.redo = () => {
|
|
44
|
+
originalRedo();
|
|
45
|
+
this[propertyKey] = h.current();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
histories.set(this, h);
|
|
49
|
+
}
|
|
50
|
+
return histories.get(this) as HistoryElement<unknown>;
|
|
51
|
+
},
|
|
52
|
+
enumerable: false,
|
|
53
|
+
configurable: true,
|
|
54
|
+
});
|
|
38
55
|
});
|
|
39
56
|
};
|
|
40
57
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
import {
|
|
3
|
+
persistedSignal,
|
|
4
|
+
type PersistedSignalOptions,
|
|
5
|
+
} from "@praxisjs/core/internal";
|
|
2
6
|
import type { Signal } from "@praxisjs/shared";
|
|
3
7
|
|
|
4
8
|
const signalMap = new WeakMap<object, Map<string, Signal<unknown>>>();
|
|
5
9
|
const initMap = new WeakMap<object, Set<string>>();
|
|
6
10
|
|
|
7
|
-
function isInitialized(instance: object, propKey: string): boolean {
|
|
8
|
-
return initMap.get(instance)?.has(propKey) ?? false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
11
|
function markInitialized(instance: object, propKey: string): void {
|
|
12
12
|
if (!initMap.has(instance)) {
|
|
13
13
|
initMap.set(instance, new Set());
|
|
@@ -40,36 +40,45 @@ export function Persisted<T>(
|
|
|
40
40
|
key?: string,
|
|
41
41
|
options: PersistedSignalOptions<T> = {},
|
|
42
42
|
) {
|
|
43
|
-
return function (
|
|
44
|
-
|
|
43
|
+
return function (
|
|
44
|
+
_value: undefined,
|
|
45
|
+
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
46
|
+
): void {
|
|
47
|
+
context.addInitializer(function (this: unknown) {
|
|
48
|
+
const instance = this as object;
|
|
49
|
+
const propertyKey = context.name as string;
|
|
50
|
+
const storageKey = key ?? propertyKey;
|
|
51
|
+
const initialValue = (instance as Record<string, unknown>)[
|
|
52
|
+
propertyKey
|
|
53
|
+
] as T;
|
|
54
|
+
|
|
55
|
+
Reflect.deleteProperty(instance, propertyKey);
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!isInitialized(this, propertyKey)) {
|
|
49
|
-
return undefined as T;
|
|
50
|
-
}
|
|
57
|
+
markInitialized(instance, propertyKey);
|
|
58
|
+
getOrCreateSignal(instance, storageKey, initialValue, options);
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
Object.defineProperty(instance, propertyKey, {
|
|
61
|
+
get(): T {
|
|
62
|
+
return getOrCreateSignal<T>(
|
|
63
|
+
instance,
|
|
64
|
+
storageKey,
|
|
65
|
+
undefined as T,
|
|
66
|
+
options,
|
|
67
|
+
)();
|
|
68
|
+
},
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
},
|
|
70
|
+
set(value: T): void {
|
|
71
|
+
getOrCreateSignal<T>(
|
|
72
|
+
instance,
|
|
73
|
+
storageKey,
|
|
74
|
+
undefined as T,
|
|
75
|
+
options,
|
|
76
|
+
).set(value);
|
|
77
|
+
},
|
|
70
78
|
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
});
|
|
73
82
|
});
|
|
74
83
|
};
|
|
75
84
|
}
|
package/src/properties/prop.ts
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
2
|
|
|
3
3
|
export function Prop() {
|
|
4
|
-
return function (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
return function (
|
|
5
|
+
_value: undefined,
|
|
6
|
+
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
7
|
+
): void {
|
|
8
|
+
context.addInitializer(function (this: unknown) {
|
|
9
|
+
const instance = this as StatefulComponent;
|
|
10
|
+
const name = context.name as string;
|
|
11
|
+
const raw = instance as unknown as Record<string, unknown>;
|
|
12
|
+
const defaultValue = raw[name];
|
|
13
|
+
Reflect.deleteProperty(raw, name);
|
|
14
|
+
|
|
15
|
+
instance._defaults[name] = defaultValue;
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(instance, name, {
|
|
18
|
+
get(this: StatefulComponent) {
|
|
19
|
+
const fromParent = this._rawProps[name];
|
|
20
|
+
if (fromParent !== undefined) {
|
|
21
|
+
return typeof fromParent === "function"
|
|
22
|
+
? (fromParent as () => unknown)()
|
|
23
|
+
: fromParent;
|
|
24
|
+
}
|
|
25
|
+
return this._defaults[name];
|
|
26
|
+
},
|
|
27
|
+
set(this: StatefulComponent, value: unknown) {
|
|
28
|
+
this._defaults[name] = value;
|
|
29
|
+
},
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
});
|
|
16
33
|
});
|
|
17
34
|
};
|
|
18
35
|
}
|
package/src/properties/slot.ts
CHANGED
|
@@ -1,75 +1,71 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
type Children,
|
|
4
|
-
type ChildrenInternal,
|
|
5
|
-
flattenChildren,
|
|
6
|
-
type VNode,
|
|
7
|
-
} from "@praxisjs/shared";
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
8
2
|
|
|
9
|
-
const slotsMap = new WeakMap<object, Map<string,
|
|
3
|
+
const slotsMap = new WeakMap<object, Map<string, unknown[]>>();
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export function resolveSlots(
|
|
16
|
-
children: ChildrenInternal | ChildrenInternal[] | undefined,
|
|
17
|
-
): Map<string, ChildrenInternal[]> {
|
|
18
|
-
const slots = new Map<string, ChildrenInternal[]>();
|
|
19
|
-
const defaultSlot: ChildrenInternal[] = [];
|
|
5
|
+
function resolveSlots(children: unknown): Map<string, unknown[]> {
|
|
6
|
+
const slots = new Map<string, unknown[]>();
|
|
7
|
+
const defaultSlot: unknown[] = [];
|
|
20
8
|
slots.set("default", defaultSlot);
|
|
21
9
|
|
|
22
|
-
if (
|
|
10
|
+
if (children == null) return slots;
|
|
23
11
|
|
|
24
|
-
const arr
|
|
12
|
+
const arr = Array.isArray(children)
|
|
13
|
+
? (children as unknown[]).flat(Infinity)
|
|
14
|
+
: [children];
|
|
25
15
|
|
|
26
|
-
for (const child of arr
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
for (const child of arr) {
|
|
17
|
+
// Named slots via `slot` attribute on DOM elements
|
|
18
|
+
if (child instanceof Element) {
|
|
19
|
+
const slotName = child.getAttribute("slot");
|
|
20
|
+
if (slotName) {
|
|
21
|
+
child.removeAttribute("slot");
|
|
22
|
+
if (!slots.has(slotName)) slots.set(slotName, []);
|
|
23
|
+
(slots.get(slotName) as unknown[]).push(child);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
36
26
|
}
|
|
27
|
+
if (child != null) defaultSlot.push(child);
|
|
37
28
|
}
|
|
38
29
|
|
|
39
30
|
return slots;
|
|
40
31
|
}
|
|
41
32
|
|
|
42
|
-
export function initSlots(
|
|
43
|
-
instance: object,
|
|
44
|
-
children: Children | undefined,
|
|
45
|
-
): void {
|
|
33
|
+
export function initSlots(instance: object, children: unknown): void {
|
|
46
34
|
slotsMap.set(instance, resolveSlots(children));
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
export function getSlot(instance: object, name: string):
|
|
37
|
+
export function getSlot(instance: object, name: string): unknown[] {
|
|
50
38
|
return slotsMap.get(instance)?.get(name) ?? [];
|
|
51
39
|
}
|
|
52
40
|
|
|
53
41
|
export function Slot(name?: string) {
|
|
54
|
-
return function (
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
return function (
|
|
43
|
+
_value: undefined,
|
|
44
|
+
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
45
|
+
): void {
|
|
46
|
+
context.addInitializer(function (this: unknown) {
|
|
47
|
+
const instance = this as StatefulComponent;
|
|
48
|
+
const propKey = context.name as string;
|
|
49
|
+
const slotName = name ?? (propKey === "default" ? "default" : propKey);
|
|
50
|
+
|
|
51
|
+
Reflect.deleteProperty(instance, propKey);
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
Object.defineProperty(instance, propKey, {
|
|
54
|
+
get(this: StatefulComponent): unknown[] {
|
|
55
|
+
return getSlot(this, slotName);
|
|
56
|
+
},
|
|
62
57
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
set(_value: unknown): void {
|
|
59
|
+
if (process.env.NODE_ENV !== "production") {
|
|
60
|
+
console.warn(
|
|
61
|
+
`[Slot] "${propKey}" is a slot and cannot be assigned directly. Slots are filled by the parent component.`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
});
|
|
73
69
|
});
|
|
74
70
|
};
|
|
75
71
|
}
|
package/src/properties/state.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
import { signal } from "@praxisjs/core/internal";
|
|
3
3
|
|
|
4
4
|
export function State() {
|
|
5
|
-
return function (
|
|
6
|
-
|
|
5
|
+
return function (
|
|
6
|
+
_value: undefined,
|
|
7
|
+
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
8
|
+
): void {
|
|
9
|
+
context.addInitializer(function (this: unknown) {
|
|
10
|
+
const instance = this as StatefulComponent & Record<string, unknown>;
|
|
11
|
+
const name = context.name as string;
|
|
12
|
+
const initialValue = instance[name];
|
|
13
|
+
Reflect.deleteProperty(instance, name);
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
configurable: true,
|
|
15
|
+
const sig = signal(initialValue);
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(instance, name, {
|
|
18
|
+
get() {
|
|
19
|
+
return sig();
|
|
20
|
+
},
|
|
21
|
+
set(value: unknown) {
|
|
22
|
+
instance._stateDirty = true;
|
|
23
|
+
sig.set(value);
|
|
24
|
+
},
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
});
|
|
22
28
|
});
|
|
23
29
|
};
|
|
24
30
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/component/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAmC,MAAM,gBAAgB,CAAC;AAuBrF,wBAAgB,SAAS,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,aAAa,EACvE,WAAW,EAAE,CAAC,GACb,CAAC,CAqBH"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { VALID_LIFECYCLE_HOOK_SIGNATURES } from "@praxisjs/core";
|
|
2
|
-
function getAllMethods(proto) {
|
|
3
|
-
const methods = [];
|
|
4
|
-
let current = proto;
|
|
5
|
-
while (current !== null && current !== Object.prototype) {
|
|
6
|
-
const names = Object.getOwnPropertyNames(current);
|
|
7
|
-
for (const name of names) {
|
|
8
|
-
if (name !== "constructor" &&
|
|
9
|
-
typeof current[name] === "function") {
|
|
10
|
-
if (!methods.includes(name))
|
|
11
|
-
methods.push(name);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
current = Object.getPrototypeOf(current);
|
|
15
|
-
}
|
|
16
|
-
return methods;
|
|
17
|
-
}
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
export function LifeCycle(constructor) {
|
|
20
|
-
if (process.env.NODE_ENV === "production")
|
|
21
|
-
return constructor;
|
|
22
|
-
const validHooks = new Set(Object.keys(VALID_LIFECYCLE_HOOK_SIGNATURES));
|
|
23
|
-
const proto = constructor.prototype;
|
|
24
|
-
const allMethods = getAllMethods(proto);
|
|
25
|
-
for (const method of allMethods) {
|
|
26
|
-
if (!method.startsWith("on"))
|
|
27
|
-
continue;
|
|
28
|
-
if (!validHooks.has(method)) {
|
|
29
|
-
console.warn(`[LifeCycle] "${constructor.name}.${method}" appears to be a lifecycle hook but is not recognized.\n` +
|
|
30
|
-
`Valid hooks: ${[...validHooks].join(", ")}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return constructor;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/component/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AAErF,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,OAAO,GAAkB,KAAK,CAAC;IAEnC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IACE,IAAI,KAAK,aAAa;gBACtB,OAAQ,OAAmC,CAAC,IAAI,CAAC,KAAK,UAAU,EAChE,CAAC;gBACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QACD,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAkB,CAAC;IAC5D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,SAAS,CACvB,WAAc;IAEd,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QAAE,OAAO,WAAW,CAAC;IAE9D,MAAM,UAAU,GAAG,IAAI,GAAG,CACxB,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAC7C,CAAC;IACF,MAAM,KAAK,GAAG,WAAW,CAAC,SAAoC,CAAC;IAE/D,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACxC,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QAEvC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CACV,gBAAgB,WAAW,CAAC,IAAI,IAAI,MAAM,2DAA2D;gBACnG,gBAAgB,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC/C,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ComponentInstance } from "@praxisjs/shared";
|
|
2
|
-
type PropsRecord = Record<string, unknown>;
|
|
3
|
-
export declare function Memoize(areEqual?: (prev: PropsRecord, next: PropsRecord) => boolean): <T extends new (...args: any[]) => ComponentInstance>(constructor: T) => T;
|
|
4
|
-
export {};
|
|
5
|
-
//# sourceMappingURL=memoize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/component/memoize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAiB3C,wBAAgB,OAAO,CACrB,QAAQ,GAAE,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,KAAK,OAAsB,IAGzD,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,iBAAiB,EAClE,aAAa,CAAC,KACb,CAAC,CAKL"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function shallowEqual(a, b) {
|
|
2
|
-
const keysA = Object.keys(a);
|
|
3
|
-
const keysB = Object.keys(b);
|
|
4
|
-
if (keysA.length !== keysB.length)
|
|
5
|
-
return false;
|
|
6
|
-
const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(b);
|
|
7
|
-
for (const aKey of keysA) {
|
|
8
|
-
if (!bHasOwnProperty(aKey))
|
|
9
|
-
return false;
|
|
10
|
-
if (!Object.is(a[aKey], b[aKey]))
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
export function Memoize(areEqual = shallowEqual) {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
return function (constructor) {
|
|
18
|
-
constructor._isMemorized = true;
|
|
19
|
-
constructor._arePropsEqual = areEqual;
|
|
20
|
-
return constructor;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=memoize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/component/memoize.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,CAAc,EAAE,CAAc;IAClD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE7B,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEhD,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEhE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,WAA8D,YAAY;IAE1E,8DAA8D;IAC9D,OAAO,UACL,WAAc;QAEb,WAA4C,CAAC,YAAY,GAAG,IAAI,CAAC;QACjE,WAA4C,CAAC,cAAc,GAAG,QAAQ,CAAC;QACxE,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type BaseComponent, VALID_LIFECYCLE_HOOK_SIGNATURES } from "@praxisjs/core";
|
|
2
|
-
|
|
3
|
-
function getAllMethods(proto: object): string[] {
|
|
4
|
-
const methods: string[] = [];
|
|
5
|
-
let current: object | null = proto;
|
|
6
|
-
|
|
7
|
-
while (current !== null && current !== Object.prototype) {
|
|
8
|
-
const names = Object.getOwnPropertyNames(current);
|
|
9
|
-
for (const name of names) {
|
|
10
|
-
if (
|
|
11
|
-
name !== "constructor" &&
|
|
12
|
-
typeof (current as Record<string, unknown>)[name] === "function"
|
|
13
|
-
) {
|
|
14
|
-
if (!methods.includes(name)) methods.push(name);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
current = Object.getPrototypeOf(current) as object | null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return methods;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
export function LifeCycle<T extends new (...args: any[]) => BaseComponent>(
|
|
25
|
-
constructor: T,
|
|
26
|
-
): T {
|
|
27
|
-
if (process.env.NODE_ENV === "production") return constructor;
|
|
28
|
-
|
|
29
|
-
const validHooks = new Set<string>(
|
|
30
|
-
Object.keys(VALID_LIFECYCLE_HOOK_SIGNATURES),
|
|
31
|
-
);
|
|
32
|
-
const proto = constructor.prototype as Record<string, unknown>;
|
|
33
|
-
|
|
34
|
-
const allMethods = getAllMethods(proto);
|
|
35
|
-
for (const method of allMethods) {
|
|
36
|
-
if (!method.startsWith("on")) continue;
|
|
37
|
-
|
|
38
|
-
if (!validHooks.has(method)) {
|
|
39
|
-
console.warn(
|
|
40
|
-
`[LifeCycle] "${constructor.name}.${method}" appears to be a lifecycle hook but is not recognized.\n` +
|
|
41
|
-
`Valid hooks: ${[...validHooks].join(", ")}`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return constructor;
|
|
47
|
-
}
|
package/src/component/memoize.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ComponentInstance } from "@praxisjs/shared";
|
|
2
|
-
|
|
3
|
-
type PropsRecord = Record<string, unknown>;
|
|
4
|
-
|
|
5
|
-
function shallowEqual(a: PropsRecord, b: PropsRecord) {
|
|
6
|
-
const keysA = Object.keys(a);
|
|
7
|
-
const keysB = Object.keys(b);
|
|
8
|
-
|
|
9
|
-
if (keysA.length !== keysB.length) return false;
|
|
10
|
-
|
|
11
|
-
const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(b);
|
|
12
|
-
|
|
13
|
-
for (const aKey of keysA) {
|
|
14
|
-
if (!bHasOwnProperty(aKey)) return false;
|
|
15
|
-
if (!Object.is(a[aKey], b[aKey])) return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function Memoize(
|
|
21
|
-
areEqual: (prev: PropsRecord, next: PropsRecord) => boolean = shallowEqual,
|
|
22
|
-
) {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
return function <T extends new (...args: any[]) => ComponentInstance>(
|
|
25
|
-
constructor: T,
|
|
26
|
-
): T {
|
|
27
|
-
(constructor as unknown as ComponentInstance)._isMemorized = true;
|
|
28
|
-
(constructor as unknown as ComponentInstance)._arePropsEqual = areEqual;
|
|
29
|
-
return constructor;
|
|
30
|
-
};
|
|
31
|
-
}
|