@praxisjs/decorators 0.2.0 → 0.4.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 +34 -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/computed.d.ts +3 -0
- package/dist/properties/computed.d.ts.map +1 -0
- package/dist/properties/computed.js +15 -0
- package/dist/properties/computed.js.map +1 -0
- 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/index.d.ts +1 -0
- package/dist/properties/index.d.ts.map +1 -1
- package/dist/properties/index.js +1 -0
- package/dist/properties/index.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 +11 -2
- package/src/properties/computed.ts +20 -0
- package/src/properties/history.ts +49 -32
- package/src/properties/index.ts +1 -0
- 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,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
|
-
}
|