@praxisjs/decorators 1.7.0 → 2.0.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 +33 -0
- package/dist/component/component.d.ts +1 -1
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/component.js +8 -15
- package/dist/component/component.js.map +1 -1
- package/dist/component/lazy.d.ts +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +44 -36
- package/dist/component/lazy.js.map +1 -1
- package/dist/create-class-decorator.d.ts +27 -5
- package/dist/create-class-decorator.d.ts.map +1 -1
- package/dist/create-class-decorator.js +53 -18
- package/dist/create-class-decorator.js.map +1 -1
- package/dist/create-field-decorator.d.ts +42 -3
- package/dist/create-field-decorator.d.ts.map +1 -1
- package/dist/create-field-decorator.js +63 -27
- package/dist/create-field-decorator.js.map +1 -1
- package/dist/create-getter-decorator.d.ts +81 -16
- package/dist/create-getter-decorator.d.ts.map +1 -1
- package/dist/create-getter-decorator.js +127 -15
- package/dist/create-getter-decorator.js.map +1 -1
- package/dist/create-lifecycle-method-decorator.d.ts +21 -3
- package/dist/create-lifecycle-method-decorator.d.ts.map +1 -1
- package/dist/create-lifecycle-method-decorator.js +25 -18
- package/dist/create-lifecycle-method-decorator.js.map +1 -1
- package/dist/create-method-decorator.d.ts +43 -3
- package/dist/create-method-decorator.d.ts.map +1 -1
- package/dist/create-method-decorator.js +49 -8
- package/dist/create-method-decorator.js.map +1 -1
- package/dist/events/command.d.ts +2 -1
- package/dist/events/command.d.ts.map +1 -1
- package/dist/events/command.js +10 -8
- package/dist/events/command.js.map +1 -1
- package/dist/events/emit.d.ts +2 -2
- package/dist/events/emit.d.ts.map +1 -1
- package/dist/events/emit.js +18 -24
- package/dist/events/emit.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 +12 -14
- package/dist/events/on-command.js.map +1 -1
- package/dist/field.d.ts +51 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +82 -0
- package/dist/field.js.map +1 -0
- package/dist/functions/bind.d.ts +2 -1
- package/dist/functions/bind.d.ts.map +1 -1
- package/dist/functions/bind.js +4 -4
- package/dist/functions/bind.js.map +1 -1
- package/dist/functions/debounce.d.ts +2 -2
- package/dist/functions/debounce.d.ts.map +1 -1
- package/dist/functions/debounce.js +25 -23
- 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 +38 -40
- 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 +41 -40
- 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 +10 -14
- 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 +21 -23
- 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 +12 -14
- package/dist/functions/throttle.js.map +1 -1
- package/dist/functions/until.d.ts +2 -1
- package/dist/functions/until.d.ts.map +1 -1
- package/dist/functions/until.js +13 -14
- package/dist/functions/until.js.map +1 -1
- package/dist/functions/watch.d.ts +1 -1
- package/dist/functions/watch.d.ts.map +1 -1
- package/dist/functions/watch.js +36 -34
- package/dist/functions/watch.js.map +1 -1
- package/dist/functions/when.d.ts +1 -1
- package/dist/functions/when.d.ts.map +1 -1
- package/dist/functions/when.js +19 -21
- package/dist/functions/when.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +24 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +55 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/properties/compose.d.ts +3 -2
- package/dist/properties/compose.d.ts.map +1 -1
- package/dist/properties/compose.js +33 -19
- package/dist/properties/compose.js.map +1 -1
- package/dist/properties/computed.d.ts +12 -10
- package/dist/properties/computed.d.ts.map +1 -1
- package/dist/properties/computed.js +26 -21
- package/dist/properties/computed.js.map +1 -1
- package/dist/properties/deep-state.d.ts +2 -1
- package/dist/properties/deep-state.d.ts.map +1 -1
- package/dist/properties/deep-state.js +66 -60
- package/dist/properties/deep-state.js.map +1 -1
- package/dist/properties/function-prop.d.ts +2 -1
- package/dist/properties/function-prop.d.ts.map +1 -1
- package/dist/properties/function-prop.js +20 -22
- package/dist/properties/function-prop.js.map +1 -1
- package/dist/properties/history.d.ts +2 -2
- package/dist/properties/history.d.ts.map +1 -1
- package/dist/properties/history.js +34 -33
- 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 +2 -1
- package/dist/properties/persisted.d.ts.map +1 -1
- package/dist/properties/persisted.js +24 -18
- 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 +26 -22
- package/dist/properties/prop.js.map +1 -1
- package/dist/properties/ref.d.ts +2 -1
- package/dist/properties/ref.d.ts.map +1 -1
- package/dist/properties/ref.js +11 -8
- package/dist/properties/ref.js.map +1 -1
- package/dist/properties/resource.d.ts.map +1 -1
- package/dist/properties/resource.js +21 -16
- package/dist/properties/resource.js.map +1 -1
- package/dist/properties/selector.d.ts +12 -0
- package/dist/properties/selector.d.ts.map +1 -0
- package/dist/properties/selector.js +25 -0
- package/dist/properties/selector.js.map +1 -0
- package/dist/properties/slot.d.ts +2 -1
- package/dist/properties/slot.d.ts.map +1 -1
- package/dist/properties/slot.js +22 -20
- package/dist/properties/slot.js.map +1 -1
- package/dist/properties/state.d.ts.map +1 -1
- package/dist/properties/state.js +27 -16
- package/dist/properties/state.js.map +1 -1
- package/dist/properties/synced.d.ts +2 -1
- package/dist/properties/synced.d.ts.map +1 -1
- package/dist/properties/synced.js +27 -19
- package/dist/properties/synced.js.map +1 -1
- package/dist/shared-method.d.ts +14 -0
- package/dist/shared-method.d.ts.map +1 -0
- package/dist/shared-method.js +87 -0
- package/dist/shared-method.js.map +1 -0
- package/package.json +14 -5
- package/src/component/component.ts +8 -27
- package/src/component/lazy.ts +51 -41
- package/src/create-class-decorator.ts +90 -31
- package/src/create-field-decorator.ts +120 -43
- package/src/create-getter-decorator.ts +263 -66
- package/src/create-lifecycle-method-decorator.ts +50 -28
- package/src/create-method-decorator.ts +119 -13
- package/src/events/command.ts +11 -9
- package/src/events/emit.ts +16 -22
- package/src/events/on-command.ts +17 -18
- package/src/field.ts +116 -0
- package/src/functions/bind.ts +4 -4
- package/src/functions/debounce.ts +25 -23
- package/src/functions/log.ts +44 -46
- package/src/functions/memo.ts +39 -37
- package/src/functions/once.ts +10 -13
- package/src/functions/retry.ts +19 -21
- package/src/functions/throttle.ts +12 -13
- package/src/functions/until.ts +14 -14
- package/src/functions/watch.ts +37 -36
- package/src/functions/when.ts +18 -20
- package/src/index.ts +12 -5
- package/src/lifecycle.ts +74 -0
- package/src/properties/compose.ts +33 -20
- package/src/properties/computed.ts +35 -45
- package/src/properties/deep-state.ts +66 -64
- package/src/properties/function-prop.ts +25 -27
- package/src/properties/history.ts +34 -35
- package/src/properties/index.ts +1 -0
- package/src/properties/persisted.ts +30 -20
- package/src/properties/prop.ts +30 -22
- package/src/properties/ref.ts +12 -10
- package/src/properties/resource.ts +22 -17
- package/src/properties/selector.ts +45 -0
- package/src/properties/slot.ts +28 -22
- package/src/properties/state.ts +32 -16
- package/src/properties/synced.ts +31 -19
- package/src/shared-method.ts +101 -0
- package/dist/__tests__/component.test.d.ts +0 -2
- package/dist/__tests__/component.test.d.ts.map +0 -1
- package/dist/__tests__/component.test.js +0 -147
- package/dist/__tests__/component.test.js.map +0 -1
- package/dist/__tests__/compose.test.d.ts +0 -2
- package/dist/__tests__/compose.test.d.ts.map +0 -1
- package/dist/__tests__/compose.test.js +0 -164
- package/dist/__tests__/compose.test.js.map +0 -1
- package/dist/__tests__/deep-state.test.d.ts +0 -2
- package/dist/__tests__/deep-state.test.d.ts.map +0 -1
- package/dist/__tests__/deep-state.test.js +0 -221
- package/dist/__tests__/deep-state.test.js.map +0 -1
- package/dist/__tests__/events.test.d.ts +0 -2
- package/dist/__tests__/events.test.d.ts.map +0 -1
- package/dist/__tests__/events.test.js +0 -295
- package/dist/__tests__/events.test.js.map +0 -1
- package/dist/__tests__/functions.test.d.ts +0 -2
- package/dist/__tests__/functions.test.d.ts.map +0 -1
- package/dist/__tests__/functions.test.js +0 -618
- package/dist/__tests__/functions.test.js.map +0 -1
- package/dist/__tests__/lazy.test.d.ts +0 -2
- package/dist/__tests__/lazy.test.d.ts.map +0 -1
- package/dist/__tests__/lazy.test.js +0 -227
- package/dist/__tests__/lazy.test.js.map +0 -1
- package/dist/__tests__/memo.test.d.ts +0 -2
- package/dist/__tests__/memo.test.d.ts.map +0 -1
- package/dist/__tests__/memo.test.js +0 -249
- package/dist/__tests__/memo.test.js.map +0 -1
- package/dist/__tests__/properties-browser.test.d.ts +0 -2
- package/dist/__tests__/properties-browser.test.d.ts.map +0 -1
- package/dist/__tests__/properties-browser.test.js +0 -227
- package/dist/__tests__/properties-browser.test.js.map +0 -1
- package/dist/__tests__/properties.test.d.ts +0 -2
- package/dist/__tests__/properties.test.d.ts.map +0 -1
- package/dist/__tests__/properties.test.js +0 -1253
- package/dist/__tests__/properties.test.js.map +0 -1
- package/dist/__tests__/ref.test.d.ts +0 -2
- package/dist/__tests__/ref.test.d.ts.map +0 -1
- package/dist/__tests__/ref.test.js +0 -106
- package/dist/__tests__/ref.test.js.map +0 -1
- package/dist/__tests__/resource.test.d.ts +0 -2
- package/dist/__tests__/resource.test.d.ts.map +0 -1
- package/dist/__tests__/resource.test.js +0 -217
- package/dist/__tests__/resource.test.js.map +0 -1
- package/dist/__tests__/slot.test.d.ts +0 -2
- package/dist/__tests__/slot.test.d.ts.map +0 -1
- package/dist/__tests__/slot.test.js +0 -147
- package/dist/__tests__/slot.test.js.map +0 -1
- package/dist/__tests__/synced.test.d.ts +0 -2
- package/dist/__tests__/synced.test.d.ts.map +0 -1
- package/dist/__tests__/synced.test.js +0 -161
- package/dist/__tests__/synced.test.js.map +0 -1
- package/dist/__tests__/until.test.d.ts +0 -2
- package/dist/__tests__/until.test.d.ts.map +0 -1
- package/dist/__tests__/until.test.js +0 -88
- package/dist/__tests__/until.test.js.map +0 -1
- package/dist/create-accessor-decorator.d.ts +0 -14
- package/dist/create-accessor-decorator.d.ts.map +0 -1
- package/dist/create-accessor-decorator.js +0 -27
- package/dist/create-accessor-decorator.js.map +0 -1
- package/src/__tests__/component.test.ts +0 -167
- package/src/__tests__/compose.test.ts +0 -202
- package/src/__tests__/deep-state.test.ts +0 -265
- package/src/__tests__/events.test.ts +0 -366
- package/src/__tests__/functions.test.ts +0 -803
- package/src/__tests__/lazy.test.ts +0 -296
- package/src/__tests__/memo.test.ts +0 -293
- package/src/__tests__/properties-browser.test.ts +0 -288
- package/src/__tests__/properties.test.ts +0 -1556
- package/src/__tests__/ref.test.ts +0 -131
- package/src/__tests__/resource.test.ts +0 -246
- package/src/__tests__/slot.test.ts +0 -179
- package/src/__tests__/synced.test.ts +0 -193
- package/src/__tests__/until.test.ts +0 -113
- package/src/create-accessor-decorator.ts +0 -45
- package/tsconfig.json +0 -9
|
@@ -1,32 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
import { type LifecycleCleanup } from "./lifecycle";
|
|
2
|
+
type Getter<This = object, Value = unknown> = (this: This) => Value;
|
|
3
|
+
/** A getter decorator usable on getters of classes extending `Host` whose type is assignable to `Value`. */
|
|
4
|
+
export type GetterDecorator<Host = object, Value = unknown> = <This extends Host, V extends Value>(target: (this: This) => V, context: ClassGetterDecoratorContext<This, V>) => (this: This) => V;
|
|
5
|
+
/**
|
|
6
|
+
* What a shared getter decorator installs: `get` (the original getter when absent) and `set` are
|
|
7
|
+
* shared by every instance (`this` is the instance), so per-instance state belongs in symbol slots
|
|
8
|
+
* created in `init`.
|
|
9
|
+
*/
|
|
10
|
+
export interface GetterSetup<This = object, Value = unknown> {
|
|
11
|
+
get?(this: This): Value;
|
|
12
|
+
set?(this: This, value: Value): void;
|
|
13
|
+
/** Runs once per instance, before the class's fields are initialized. */
|
|
14
|
+
init?: (instance: This) => void;
|
|
15
|
+
onMount?: (instance: This) => void;
|
|
16
|
+
onUnmount?: (instance: This) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface SharedGetterBehavior<Host = object, Value = unknown> {
|
|
19
|
+
/** Names the decorator in error messages, e.g. `"@Clamp()"`. */
|
|
20
|
+
label?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Runs once per decorated getter, when the class is defined: returns the replacement getter, or
|
|
23
|
+
* a `GetterSetup`.
|
|
24
|
+
*/
|
|
25
|
+
setup(original: Getter<Host, Value>, context: ClassGetterDecoratorContext<Host, Value>): Getter<Host, Value> | GetterSetup<Host, Value>;
|
|
26
|
+
}
|
|
27
|
+
export interface SharedWritableGetterBehavior<Host = object, Value = unknown> {
|
|
28
|
+
/** Names the decorator in error messages, e.g. `"@Overridable()"`. */
|
|
29
|
+
label?: string;
|
|
30
|
+
/** Runs once per decorated getter, when the class is defined. */
|
|
31
|
+
setup(original: Getter<Host, Value>, context: ClassGetterDecoratorContext<Host, Value>): GetterSetup<Host, Value>;
|
|
32
|
+
}
|
|
33
|
+
export interface GetterBehavior<T = object> {
|
|
34
|
+
/** Names the decorator in error messages. */
|
|
35
|
+
label?: string;
|
|
2
36
|
/**
|
|
3
37
|
* Given the original getter and the current instance, returns a function
|
|
4
38
|
* that produces the getter value. Called on every property access.
|
|
5
39
|
*/
|
|
6
|
-
wrap(original: (this: object) => unknown, instance:
|
|
40
|
+
wrap(original: (this: object) => unknown, instance: T): () => unknown;
|
|
7
41
|
}
|
|
8
|
-
export declare function createGetterDecorator(behavior: GetterBehavior): <This, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
9
42
|
export interface WritableGetterBinding {
|
|
10
43
|
get: () => unknown;
|
|
11
44
|
set?: (value: unknown) => void;
|
|
12
45
|
}
|
|
13
|
-
export interface WritableGetterBehavior {
|
|
46
|
+
export interface WritableGetterBehavior<T = object> {
|
|
47
|
+
/** Names the decorator in error messages. */
|
|
48
|
+
label?: string;
|
|
14
49
|
/**
|
|
15
|
-
* Called once per instance during construction. Returns the get/set pair
|
|
16
|
-
* that
|
|
17
|
-
*
|
|
18
|
-
* may still see a setter if one is declared in the class body).
|
|
50
|
+
* Called once per instance during construction. Returns the get/set pair the property reads and
|
|
51
|
+
* writes through for that instance. If `set` is omitted, assigning the property throws a
|
|
52
|
+
* `TypeError`, as for a getter without a setter.
|
|
19
53
|
*/
|
|
20
|
-
bind(instance:
|
|
54
|
+
bind(instance: T, name: string | symbol, original: (this: object) => unknown): WritableGetterBinding;
|
|
21
55
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
56
|
+
export interface GetterObserverBehavior<T = object, Value = unknown> {
|
|
57
|
+
/** Names the decorator in error messages. */
|
|
58
|
+
label?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Called once per instance, while it is built and before its fields are initialized. Use it to
|
|
61
|
+
* set up observation without changing the getter's value. A function it returns runs when the
|
|
62
|
+
* instance unmounts.
|
|
63
|
+
*/
|
|
64
|
+
observe?(getter: (this: object) => Value, instance: T, name: string): (() => void) | undefined | void;
|
|
24
65
|
/**
|
|
25
|
-
* Called
|
|
26
|
-
*
|
|
27
|
-
* changing its return value (e.g. tracking changes for devtools).
|
|
66
|
+
* Called on every mount of each instance, once its fields are set. What it returns (a stop
|
|
67
|
+
* function or an effect) is undone on unmount.
|
|
28
68
|
*/
|
|
29
|
-
|
|
69
|
+
register?(getter: (this: object) => Value, instance: T, name: string): LifecycleCleanup;
|
|
30
70
|
}
|
|
31
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Builds a getter decorator that changes what a getter returns.
|
|
73
|
+
*
|
|
74
|
+
* With `setup`, the recommended form, the replacement getter is created once per decorated getter
|
|
75
|
+
* and shared by every instance: neither building an instance nor reading the getter allocates.
|
|
76
|
+
*
|
|
77
|
+
* With `wrap`, a function is created on every read.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createGetterDecorator<Host = object, Value = unknown>(behavior: SharedGetterBehavior<Host, Value>): GetterDecorator<Host, Value>;
|
|
80
|
+
export declare function createGetterDecorator(behavior: GetterBehavior): <This, T>(target: (this: This) => T, context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
81
|
+
/**
|
|
82
|
+
* Builds a getter decorator that owns writes to the property as well as reads.
|
|
83
|
+
*
|
|
84
|
+
* With `setup`, the recommended form, `get` and `set` are created once per decorated getter and
|
|
85
|
+
* shared by every instance.
|
|
86
|
+
*
|
|
87
|
+
* With `bind`, a get/set pair is created for each instance while it is built.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createWritableGetterDecorator<Host = object, Value = unknown>(behavior: SharedWritableGetterBehavior<Host, Value>): GetterDecorator<Host, Value>;
|
|
90
|
+
export declare function createWritableGetterDecorator(behavior: WritableGetterBehavior): <This, T>(target: (this: This) => T, context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
91
|
+
/**
|
|
92
|
+
* Builds a getter decorator that observes the getter (for logging, devtools, syncing) without
|
|
93
|
+
* changing its value: `observe` runs once per instance while it is built, `register` on every mount.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createGetterObserverDecorator<T = object, Value = unknown>(behavior: GetterObserverBehavior<T, Value>): <This extends T, V extends Value>(target: (this: This) => V, context: ClassGetterDecoratorContext<This, V>) => void;
|
|
96
|
+
export {};
|
|
32
97
|
//# sourceMappingURL=create-getter-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-getter-decorator.d.ts","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-getter-decorator.d.ts","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAA2C,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE7F,KAAK,MAAM,CAAC,IAAI,GAAG,MAAM,EAAE,KAAK,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC;AAEpE,4GAA4G;AAC5G,MAAM,MAAM,eAAe,CAAC,IAAI,GAAG,MAAM,EAAE,KAAK,GAAG,OAAO,IAAI,CAAC,IAAI,SAAS,IAAI,EAAE,CAAC,SAAS,KAAK,EAC/F,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,OAAO,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC1C,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,IAAI,GAAG,MAAM,EAAE,KAAK,GAAG,OAAO;IACzD,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC;IACxB,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACrC,yEAAyE;IACzE,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,oBAAoB,CAAC,IAAI,GAAG,MAAM,EAAE,KAAK,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,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,OAAO,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC;AAQ5G;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,GAAG,OAAO,EACvE,QAAQ,EAAE,sBAAsB,CAAC,CAAC,EAAE,KAAK,CAAC,IAMzB,IAAI,SAAS,CAAC,EAAE,CAAC,SAAS,KAAK,EAC9C,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,SAAS,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC5C,IAAI,CAkBR"}
|
|
@@ -1,31 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { assertMemberKind, describeValue } from "./field";
|
|
2
|
+
import { addLifecycleHooks, addMountRegistration } from "./lifecycle";
|
|
3
|
+
// Replacement getter -> the getter it wraps. Lets a setter added by an inner decorator find the
|
|
4
|
+
// prototype entry after outer getter decorators replaced its getter again.
|
|
5
|
+
const wraps = new WeakMap();
|
|
6
|
+
function isFrom(get, target) {
|
|
7
|
+
for (let g = get; g !== undefined; g = wraps.get(g))
|
|
8
|
+
if (g === target)
|
|
9
|
+
return true;
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
function addSetter(target, context, get, set) {
|
|
13
|
+
const name = context.name;
|
|
14
|
+
let fallback;
|
|
15
|
+
for (let owner = (context.static ? target : Object.getPrototypeOf(target)); owner !== null; owner = Object.getPrototypeOf(owner)) {
|
|
16
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, name);
|
|
17
|
+
if (descriptor === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
if (isFrom(descriptor.get, get)) {
|
|
20
|
+
Object.defineProperty(owner, name, { get: descriptor.get, set, enumerable: descriptor.enumerable, configurable: true });
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
fallback ??= descriptor;
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(target, name, { get: fallback?.get ?? get, set, enumerable: false, configurable: true });
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function sharedGetter(behavior) {
|
|
29
|
+
const label = behavior.label ?? "This getter decorator";
|
|
30
|
+
return function (target, context) {
|
|
31
|
+
assertMemberKind(context, "getter", label);
|
|
32
|
+
const result = behavior.setup(target, context);
|
|
33
|
+
if (typeof result !== "object" && typeof result !== "function") {
|
|
34
|
+
throw new TypeError(`${label}: setup() must return a getter or a GetterSetup object, got ${describeValue(result)}.`);
|
|
35
|
+
}
|
|
36
|
+
if (result === null) {
|
|
37
|
+
throw new TypeError(`${label}: setup() must return a getter or a GetterSetup object, got null.`);
|
|
38
|
+
}
|
|
39
|
+
const spec = (typeof result === "function" ? { get: result } : result);
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- installed on the class, which calls them with the instance as `this`
|
|
41
|
+
const { get = target, set, init, onMount, onUnmount } = spec;
|
|
42
|
+
if (typeof get !== "function") {
|
|
43
|
+
throw new TypeError(`${label}: setup() returned a "get" that is not a function.`);
|
|
44
|
+
}
|
|
45
|
+
if (get !== target)
|
|
46
|
+
wraps.set(get, target);
|
|
47
|
+
const hooks = onMount !== undefined || onUnmount !== undefined;
|
|
48
|
+
if (hooks && context.static) {
|
|
49
|
+
throw new TypeError(`${label}: onMount/onUnmount need an instance getter, not the static "${String(context.name)}".`);
|
|
50
|
+
}
|
|
51
|
+
if (set !== undefined || init !== undefined || hooks) {
|
|
52
|
+
let installed = set === undefined;
|
|
53
|
+
context.addInitializer(function () {
|
|
54
|
+
const instance = this;
|
|
55
|
+
if (!installed)
|
|
56
|
+
installed = addSetter(instance, context, get, set);
|
|
57
|
+
init?.(instance);
|
|
58
|
+
if (hooks)
|
|
59
|
+
addLifecycleHooks(instance, onMount, onUnmount);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return get;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function wrapGetterDecorator(behavior) {
|
|
66
|
+
const label = behavior.label ?? "This getter decorator";
|
|
67
|
+
return function (target, context) {
|
|
68
|
+
assertMemberKind(context, "getter", label);
|
|
69
|
+
const getter = function () {
|
|
4
70
|
return behavior.wrap(target, this)();
|
|
5
71
|
};
|
|
72
|
+
wraps.set(getter, target);
|
|
73
|
+
return getter;
|
|
6
74
|
};
|
|
7
75
|
}
|
|
8
|
-
export function
|
|
76
|
+
export function createGetterDecorator(behavior) {
|
|
77
|
+
if (!("setup" in behavior))
|
|
78
|
+
return wrapGetterDecorator(behavior);
|
|
79
|
+
return sharedGetter(behavior);
|
|
80
|
+
}
|
|
81
|
+
function bindWritableGetter(behavior) {
|
|
82
|
+
const label = behavior.label ?? "This getter decorator";
|
|
9
83
|
return function (target, context) {
|
|
84
|
+
assertMemberKind(context, "getter", label);
|
|
85
|
+
const name = context.name;
|
|
86
|
+
// Each instance's binding lives in this slot, read through one accessor pair on the class.
|
|
87
|
+
const slot = Symbol(`praxis.getter.${String(name)}`);
|
|
88
|
+
const original = target;
|
|
89
|
+
const bindingOf = (instance) => (instance[slot] ??= behavior.bind(instance, name, original));
|
|
90
|
+
const get = function () {
|
|
91
|
+
return bindingOf(this).get();
|
|
92
|
+
};
|
|
93
|
+
const set = function (value) {
|
|
94
|
+
const write = bindingOf(this).set;
|
|
95
|
+
if (write === undefined)
|
|
96
|
+
throw new TypeError(`Cannot set property ${String(name)}, which has only a getter.`);
|
|
97
|
+
write(value);
|
|
98
|
+
};
|
|
99
|
+
wraps.set(get, original);
|
|
100
|
+
let installed = false;
|
|
10
101
|
context.addInitializer(function () {
|
|
11
102
|
const instance = this;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
configurable: true,
|
|
16
|
-
enumerable: false,
|
|
17
|
-
};
|
|
18
|
-
if (binding.set !== undefined)
|
|
19
|
-
descriptor.set = binding.set;
|
|
20
|
-
Object.defineProperty(instance, context.name, descriptor);
|
|
103
|
+
instance[slot] = behavior.bind(instance, name, original);
|
|
104
|
+
if (!installed)
|
|
105
|
+
installed = addSetter(instance, context, get, set);
|
|
21
106
|
});
|
|
22
|
-
return
|
|
107
|
+
return get;
|
|
23
108
|
};
|
|
24
109
|
}
|
|
110
|
+
export function createWritableGetterDecorator(behavior) {
|
|
111
|
+
if (!("setup" in behavior))
|
|
112
|
+
return bindWritableGetter(behavior);
|
|
113
|
+
return sharedGetter(behavior);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Builds a getter decorator that observes the getter (for logging, devtools, syncing) without
|
|
117
|
+
* changing its value: `observe` runs once per instance while it is built, `register` on every mount.
|
|
118
|
+
*/
|
|
25
119
|
export function createGetterObserverDecorator(behavior) {
|
|
120
|
+
const label = behavior.label ?? "This getter decorator";
|
|
121
|
+
if (behavior.observe === undefined && behavior.register === undefined) {
|
|
122
|
+
throw new TypeError(`${label}: createGetterObserverDecorator() needs observe() or register().`);
|
|
123
|
+
}
|
|
26
124
|
return function (target, context) {
|
|
125
|
+
assertMemberKind(context, "getter", label);
|
|
126
|
+
const name = context.name;
|
|
127
|
+
const getter = target;
|
|
128
|
+
const observes = behavior.observe !== undefined;
|
|
129
|
+
const mount = behavior.register === undefined
|
|
130
|
+
? undefined
|
|
131
|
+
: (instance, read) => behavior.register?.(read, instance, name);
|
|
27
132
|
context.addInitializer(function () {
|
|
28
|
-
|
|
133
|
+
const instance = this;
|
|
134
|
+
if (observes) {
|
|
135
|
+
const cleanup = behavior.observe?.(getter, instance, name);
|
|
136
|
+
if (typeof cleanup === "function")
|
|
137
|
+
addLifecycleHooks(instance, undefined, cleanup);
|
|
138
|
+
}
|
|
139
|
+
if (mount !== undefined)
|
|
140
|
+
addMountRegistration(instance, mount, getter);
|
|
29
141
|
});
|
|
30
142
|
};
|
|
31
143
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-getter-decorator.js","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-getter-decorator.js","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAyB,MAAM,aAAa,CAAC;AAuF7F,gGAAgG;AAChG,2EAA2E;AAC3E,MAAM,KAAK,GAAG,IAAI,OAAO,EAAkB,CAAC;AAE5C,SAAS,MAAM,CAAC,GAAuB,EAAE,MAAc;IACrD,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAAE,IAAI,CAAC,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;IACnF,OAAO,KAAK,CAAC;AACf,CAAC;AAaD,SAAS,SAAS,CAChB,MAAc,EACd,OAAoC,EACpC,GAAW,EACX,GAA2C;IAE3C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,IAAI,QAAqC,CAAC;IAC1C,KACE,IAAI,KAAK,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAkB,EACtF,KAAK,KAAK,IAAI,EACd,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAkB,EACrD,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,IAAI,CAAgC,CAAC;QAC/F,IAAI,UAAU,KAAK,SAAS;YAAE,SAAS;QACvC,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE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,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,KAAK,SAAS,CAAC;QAChD,MAAM,KAAK,GACT,QAAQ,CAAC,QAAQ,KAAK,SAAS;YAC7B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,QAAW,EAAE,IAA6B,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChG,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,QAAQ,GAAG,IAAkB,CAAC;YACpC,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC3D,IAAI,OAAO,OAAO,KAAK,UAAU;oBAAE,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YACrF,CAAC;YACD,IAAI,KAAK,KAAK,SAAS;gBAAE,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACzE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { type LifecycleCleanup } from "./lifecycle";
|
|
3
|
+
export type { LifecycleCleanup };
|
|
4
|
+
export interface LifecycleMethodBehavior<T extends object = StatefulComponent, Args extends unknown[] = any[]> {
|
|
5
|
+
/** Names the decorator in error messages, e.g. `"@OnResize()"`. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Runs on every mount of each instance with the method bound to it. Returns what undoes the
|
|
9
|
+
* registration on unmount, if anything.
|
|
10
|
+
*/
|
|
11
|
+
register(callback: (...args: Args) => void, instance: T, name: string): (() => void) | undefined | void;
|
|
4
12
|
}
|
|
5
|
-
|
|
13
|
+
type AnyMethod = (this: any, ...args: any[]) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Builds a method decorator that calls `start` on every mount and undoes what it returned on
|
|
16
|
+
* unmount.
|
|
17
|
+
*/
|
|
18
|
+
export declare function lifecycleMethodDecorator<T extends object>(start: (instance: T, method: AnyMethod, name: string) => LifecycleCleanup, label?: string): (value: (this: T, ...args: any[]) => void, context: ClassMethodDecoratorContext<T>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a method decorator that registers the method somewhere on every mount (an event listener,
|
|
21
|
+
* a subscription) and undoes it on unmount.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createLifecycleMethodDecorator<T extends object = StatefulComponent, Args extends unknown[] = any[]>(behavior: LifecycleMethodBehavior<T, Args>): <This extends T>(value: (this: This, ...args: Args) => void, context: ClassMethodDecoratorContext<This>) => void;
|
|
6
24
|
//# sourceMappingURL=create-lifecycle-method-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-lifecycle-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-lifecycle-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1E,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAGjC,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,iBAAiB,EAAE,IAAI,SAAS,OAAO,EAAE,GAAG,GAAG,EAAE;IAC3G,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IAEH,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;CACzG;AAGD,KAAK,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAErD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,EACvD,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,gBAAgB,EACzE,KAAK,SAAoC,IAIvC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EACxC,SAAS,2BAA2B,CAAC,CAAC,CAAC,KACtC,IAAI,CAWR;AAED;;;GAGG;AAEH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,iBAAiB,EAAE,IAAI,SAAS,OAAO,EAAE,GAAG,GAAG,EAAE,EACjH,QAAQ,EAAE,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAAC,GACzC,CAAC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,OAAO,EAAE,2BAA2B,CAAC,IAAI,CAAC,KAAK,IAAI,CAMlH"}
|
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { assertMemberKind } from "./field";
|
|
2
|
+
import { addMountRegistration } from "./lifecycle";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a method decorator that calls `start` on every mount and undoes what it returned on
|
|
5
|
+
* unmount.
|
|
6
|
+
*/
|
|
7
|
+
export function lifecycleMethodDecorator(start, label = "This lifecycle method decorator") {
|
|
2
8
|
return function (
|
|
3
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
value,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (result)
|
|
14
|
-
cleanup = result;
|
|
15
|
-
};
|
|
16
|
-
instance.onUnmount = function () {
|
|
17
|
-
prevUnmount?.call(this);
|
|
18
|
-
cleanup?.();
|
|
19
|
-
cleanup = undefined;
|
|
20
|
-
};
|
|
10
|
+
value, context) {
|
|
11
|
+
assertMemberKind(context, "method", label);
|
|
12
|
+
if (context.static) {
|
|
13
|
+
throw new TypeError(`${label} decorates instance methods only, not the static method "${String(context.name)}".`);
|
|
14
|
+
}
|
|
15
|
+
const name = String(context.name);
|
|
16
|
+
const run = (instance, method) => start(instance, method, name);
|
|
17
|
+
context.addInitializer(function () {
|
|
18
|
+
addMountRegistration(this, run, value);
|
|
21
19
|
});
|
|
22
20
|
};
|
|
23
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds a method decorator that registers the method somewhere on every mount (an event listener,
|
|
24
|
+
* a subscription) and undoes it on unmount.
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
export function createLifecycleMethodDecorator(behavior) {
|
|
28
|
+
const label = behavior.label ?? "This lifecycle method decorator";
|
|
29
|
+
return lifecycleMethodDecorator((instance, method, name) => behavior.register(method.bind(instance), instance, name), label);
|
|
30
|
+
}
|
|
24
31
|
//# sourceMappingURL=create-lifecycle-method-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-lifecycle-method-decorator.js","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-lifecycle-method-decorator.js","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM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-method";
|
|
3
|
+
export type { AnyMethod };
|
|
4
|
+
export interface MethodBehavior<T = object> {
|
|
5
|
+
/** Names the decorator in error messages, e.g. `"@Confirm()"`. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Runs once per instance, while it is built: returns the function that runs in place of the
|
|
9
|
+
* method for that instance.
|
|
10
|
+
*/
|
|
11
|
+
wrap(original: (...args: any[]) => any, instance: T, name: string): (...args: any[]) => any;
|
|
4
12
|
}
|
|
5
|
-
|
|
13
|
+
/** A replacement method, with hooks that run on every mount and unmount of each instance. */
|
|
14
|
+
export interface MethodSetup<This = object, M extends AnyMethod = AnyMethod> {
|
|
15
|
+
method: M;
|
|
16
|
+
onMount?: (instance: This) => void;
|
|
17
|
+
onUnmount?: (instance: This) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface SharedMethodBehavior<Host = object, M extends AnyMethod = AnyMethod> {
|
|
20
|
+
/** Names the decorator in error messages, e.g. `"@Confirm()"`. */
|
|
21
|
+
label?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Runs once per decorated method, when the class is defined: returns the replacement, shared by
|
|
24
|
+
* every instance (`this` is the instance), or a `MethodSetup` that also has lifecycle hooks.
|
|
25
|
+
*
|
|
26
|
+
* `M` is never inferred from it, so a decorator fits every method unless `M` is given.
|
|
27
|
+
*/
|
|
28
|
+
setup(original: NoInfer<M>, context: ClassMethodDecoratorContext<Host, NoInfer<M>>): NoInfer<M> | MethodSetup<Host, NoInfer<M>>;
|
|
29
|
+
}
|
|
30
|
+
/** A method decorator usable on methods of classes extending `Host` whose type is assignable to `M`. */
|
|
31
|
+
export type MethodDecorator<Host = object, M extends AnyMethod = AnyMethod> = <This extends Host, V extends M>(value: V, context: ClassMethodDecoratorContext<This, V>) => V;
|
|
32
|
+
/**
|
|
33
|
+
* Builds a method decorator.
|
|
34
|
+
*
|
|
35
|
+
* With `setup`, the recommended form, the replacement is created once per decorated method and
|
|
36
|
+
* shared by every instance, which keeps any state in symbol slots: building an instance costs
|
|
37
|
+
* nothing.
|
|
38
|
+
*
|
|
39
|
+
* With `wrap`, a wrapper is created for each instance while it is built.
|
|
40
|
+
*
|
|
41
|
+
* Either way, reading the method from an instance returns it bound to that instance, the same
|
|
42
|
+
* function on every read, so `onClick={this.save}` works.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createMethodDecorator<Host = object, M extends AnyMethod = AnyMethod>(behavior: SharedMethodBehavior<Host, M>): MethodDecorator<Host, M>;
|
|
45
|
+
export declare function createMethodDecorator<T = object>(behavior: MethodBehavior<T>): (value: (this: object, ...args: any[]) => any, context: ClassMethodDecoratorContext<StatefulComponent>) => void;
|
|
6
46
|
//# sourceMappingURL=create-method-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,OAAO,EAAE,KAAK,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAE/D,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,MAAM;IACxC,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,CAEF,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACjC,QAAQ,EAAE,CAAC,EACX,IAAI,EAAE,MAAM,GAEX,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAC5B;AAED,6FAA6F;AAC7F,MAAM,WAAW,WAAW,CAAC,IAAI,GAAG,MAAM,EAAE,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AG,EAC5C,OAAO,EAAE,2BAA2B,CAAC,iBAAiB,CAAC,KACpD,IAAI,CAAC"}
|
|
@@ -1,16 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { assertMemberKind, describeValue } from "./field";
|
|
2
|
+
import { addLifecycleHooks } from "./lifecycle";
|
|
3
|
+
import { sharedMethod } from "./shared-method";
|
|
4
|
+
const DEFAULT_LABEL = "This method decorator";
|
|
5
|
+
function sharedMethodDecorator(behavior) {
|
|
6
|
+
const label = behavior.label ?? DEFAULT_LABEL;
|
|
7
|
+
return function (value, context) {
|
|
8
|
+
assertMemberKind(context, "method", label);
|
|
9
|
+
const result = behavior.setup(value, context);
|
|
10
|
+
const setup = typeof result === "object" && result !== null ? result : undefined;
|
|
11
|
+
const method = setup === undefined ? result : setup.method;
|
|
12
|
+
if (typeof method !== "function") {
|
|
13
|
+
throw new TypeError(`${label}: setup() must return a function or { method }, got ${describeValue(method)}.`);
|
|
14
|
+
}
|
|
15
|
+
if (setup !== undefined && (setup.onMount !== undefined || setup.onUnmount !== undefined)) {
|
|
16
|
+
if (context.static) {
|
|
17
|
+
throw new TypeError(`${label}: onMount/onUnmount need an instance method, not the static "${String(context.name)}".`);
|
|
18
|
+
}
|
|
19
|
+
const { onMount, onUnmount } = setup;
|
|
20
|
+
context.addInitializer(function () {
|
|
21
|
+
addLifecycleHooks(this, onMount, onUnmount);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return sharedMethod(context, value, method);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function wrapMethodDecorator(behavior) {
|
|
28
|
+
const label = behavior.label ?? DEFAULT_LABEL;
|
|
2
29
|
return function (
|
|
3
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
31
|
value, context) {
|
|
32
|
+
assertMemberKind(context, "method", label);
|
|
33
|
+
const name = context.name;
|
|
34
|
+
// Each instance's wrapper lives in this slot, called through one replacement on the prototype:
|
|
35
|
+
// no property definition per instance, and decorators stacked around this one keep working.
|
|
36
|
+
const slot = Symbol(`praxis.method.${name}`);
|
|
37
|
+
const wrapFor = (instance) => {
|
|
38
|
+
const wrapped = behavior.wrap(value, instance, name);
|
|
39
|
+
if (typeof wrapped !== "function") {
|
|
40
|
+
throw new TypeError(`${label}: wrap() must return a function, got ${describeValue(wrapped)}.`);
|
|
41
|
+
}
|
|
42
|
+
return wrapped;
|
|
43
|
+
};
|
|
44
|
+
const method = function (...args) {
|
|
45
|
+
// An object the constructor did not build (Object.create(prototype)) gets its wrapper here.
|
|
46
|
+
return (this[slot] ??= wrapFor(this)).apply(this, args);
|
|
47
|
+
};
|
|
5
48
|
context.addInitializer(function () {
|
|
6
|
-
|
|
7
|
-
const name = context.name;
|
|
8
|
-
Object.defineProperty(instance, name, {
|
|
9
|
-
value: behavior.wrap(value, instance, name),
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
});
|
|
49
|
+
this[slot] = wrapFor(this);
|
|
13
50
|
});
|
|
51
|
+
return sharedMethod(context, value, method);
|
|
14
52
|
};
|
|
15
53
|
}
|
|
54
|
+
export function createMethodDecorator(behavior) {
|
|
55
|
+
return "setup" in behavior ? sharedMethodDecorator(behavior) : wrapMethodDecorator(behavior);
|
|
56
|
+
}
|
|
16
57
|
//# sourceMappingURL=create-method-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-method-decorator.js","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-method-decorator.js","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAkB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAgD/D,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,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Q,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAC/F,CAAC"}
|
package/dist/events/command.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
1
2
|
export interface Command<T = void> {
|
|
2
3
|
trigger(arg: T): void;
|
|
3
4
|
subscribe(handler: (arg: T) => void): () => void;
|
|
4
5
|
}
|
|
5
6
|
export declare function createCommand<T = void>(): Command<T>;
|
|
6
|
-
export declare function Command<T = void>():
|
|
7
|
+
export declare function Command<T = void>(): FieldDecorator;
|
|
7
8
|
//# sourceMappingURL=command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/events/command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/events/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAE5E,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,IAAI;IAC/B,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAClD;AAED,wBAAgB,aAAa,CAAC,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAWpD;AAGD,wBAAgB,OAAO,CAAC,CAAC,GAAG,IAAI,KAAK,cAAc,CAWlD"}
|
package/dist/events/command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedField } from "../field";
|
|
2
2
|
export function createCommand() {
|
|
3
3
|
const handlers = new Set();
|
|
4
4
|
return {
|
|
@@ -13,13 +13,15 @@ export function createCommand() {
|
|
|
13
13
|
}
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
15
15
|
export function Command() {
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
return sharedField((name) => {
|
|
17
|
+
const command = Symbol(`praxis.command.${name}`);
|
|
18
|
+
return {
|
|
19
|
+
descriptor: {
|
|
20
|
+
get() {
|
|
21
|
+
return (this[command] ??= createCommand());
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
//# sourceMappingURL=command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/events/command.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/events/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAO5E,MAAM,UAAU,aAAa;IAC3B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC7C,OAAO;QACL,OAAO,CAAC,GAAM;YACZ,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;QACD,SAAS,CAAC,OAAO;YACf,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,OAAO;IACrB,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;QACjD,OAAO;YACL,UAAU,EAAE;gBACV,GAAG;oBACD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,aAAa,EAAK,CAAC,CAAC;gBAChD,CAAC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/events/emit.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function Emit(propName: string): (value:
|
|
1
|
+
import { type AnyMethod, type MethodContext } from "../shared-method";
|
|
2
|
+
export declare function Emit(propName: string): (value: AnyMethod, context: MethodContext) => AnyMethod;
|
|
3
3
|
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAGpF,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,IAClB,OAAO,SAAS,EAAE,SAAS,aAAa,KAAG,SAAS,CAkBtE"}
|