@praxisjs/decorators 1.5.0 → 1.6.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 +20 -0
- package/dist/__tests__/component.test.js +1 -1
- package/dist/__tests__/component.test.js.map +1 -1
- package/dist/__tests__/compose.test.js +6 -13
- package/dist/__tests__/compose.test.js.map +1 -1
- package/dist/__tests__/events.test.js +79 -1
- package/dist/__tests__/events.test.js.map +1 -1
- package/dist/__tests__/functions.test.js +1 -3
- package/dist/__tests__/functions.test.js.map +1 -1
- package/dist/__tests__/lazy.test.js +6 -6
- package/dist/__tests__/lazy.test.js.map +1 -1
- package/dist/__tests__/properties.test.js +26 -0
- package/dist/__tests__/properties.test.js.map +1 -1
- package/dist/__tests__/synced.test.js +5 -4
- package/dist/__tests__/synced.test.js.map +1 -1
- package/dist/component/lazy.js +1 -0
- package/dist/component/lazy.js.map +1 -1
- package/dist/create-class-decorator.js +1 -4
- package/dist/create-class-decorator.js.map +1 -1
- package/dist/events/command.d.ts +1 -0
- package/dist/events/command.d.ts.map +1 -1
- package/dist/events/command.js +12 -0
- package/dist/events/command.js.map +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/properties/function-prop.d.ts.map +1 -1
- package/dist/properties/function-prop.js +4 -0
- package/dist/properties/function-prop.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/events.test.ts +98 -1
- package/src/__tests__/properties.test.ts +28 -0
- package/src/events/command.ts +14 -0
- package/src/events/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/properties/function-prop.ts +8 -0
- package/tsconfig.json +2 -1
|
@@ -201,6 +201,34 @@ describe("FunctionProp decorator", () => {
|
|
|
201
201
|
|
|
202
202
|
expect((instance as unknown as Record<string, unknown>).filter).toBe(nextFilter);
|
|
203
203
|
});
|
|
204
|
+
|
|
205
|
+
it("warns on a non-function raw prop in non-production", () => {
|
|
206
|
+
const { ctx, run } = fieldCtx("filter");
|
|
207
|
+
FunctionProp()(undefined, ctx);
|
|
208
|
+
|
|
209
|
+
const instance = new TestComponent({ filter: "not-a-function" });
|
|
210
|
+
run(instance);
|
|
211
|
+
|
|
212
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
213
|
+
expect((instance as unknown as Record<string, unknown>).filter).toBe("not-a-function");
|
|
214
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("[FunctionProp]"));
|
|
215
|
+
warn.mockRestore();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("does not warn in production", () => {
|
|
219
|
+
const { ctx, run } = fieldCtx("filter");
|
|
220
|
+
FunctionProp()(undefined, ctx);
|
|
221
|
+
|
|
222
|
+
const instance = new TestComponent({ filter: "not-a-function" });
|
|
223
|
+
run(instance);
|
|
224
|
+
|
|
225
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
226
|
+
vi.stubEnv("NODE_ENV", "production");
|
|
227
|
+
expect((instance as unknown as Record<string, unknown>).filter).toBe("not-a-function");
|
|
228
|
+
expect(warn).not.toHaveBeenCalled();
|
|
229
|
+
vi.unstubAllEnvs();
|
|
230
|
+
warn.mockRestore();
|
|
231
|
+
});
|
|
204
232
|
});
|
|
205
233
|
|
|
206
234
|
// ── Computed ──────────────────────────────────────────────────────────────────
|
package/src/events/command.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
|
+
|
|
1
3
|
export interface Command<T = void> {
|
|
2
4
|
trigger(arg: T): void;
|
|
3
5
|
subscribe(handler: (arg: T) => void): () => void;
|
|
@@ -15,3 +17,15 @@ export function createCommand<T = void>(): Command<T> {
|
|
|
15
17
|
},
|
|
16
18
|
};
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
22
|
+
export function Command<T = void>() {
|
|
23
|
+
return createFieldDecorator({
|
|
24
|
+
bind(_instance, _name, _initialValue) {
|
|
25
|
+
const command = createCommand<T>();
|
|
26
|
+
return {
|
|
27
|
+
descriptor: { get: () => command },
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
package/src/events/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ export {
|
|
|
34
34
|
Ref,
|
|
35
35
|
createRef,
|
|
36
36
|
} from "./properties";
|
|
37
|
-
export {
|
|
37
|
+
export { Command, createCommand, Emit, OnCommand } from "./events";
|
|
38
38
|
export {
|
|
39
39
|
createFieldDecorator,
|
|
40
40
|
type FieldBehavior,
|
|
@@ -15,6 +15,14 @@ export function FunctionProp() {
|
|
|
15
15
|
get() {
|
|
16
16
|
const fromParent = getComponentRawProp(instance, name);
|
|
17
17
|
if (fromParent !== undefined) {
|
|
18
|
+
if (
|
|
19
|
+
process.env.NODE_ENV !== "production" &&
|
|
20
|
+
typeof fromParent !== "function"
|
|
21
|
+
) {
|
|
22
|
+
console.warn(
|
|
23
|
+
`[FunctionProp] "${name}" received a non-function value (${typeof fromParent}). @FunctionProp() expects a function.`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
18
26
|
return fromParent;
|
|
19
27
|
}
|
|
20
28
|
return getComponentDefault(instance, name);
|