@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.
Files changed (42) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/__tests__/component.test.js +1 -1
  3. package/dist/__tests__/component.test.js.map +1 -1
  4. package/dist/__tests__/compose.test.js +6 -13
  5. package/dist/__tests__/compose.test.js.map +1 -1
  6. package/dist/__tests__/events.test.js +79 -1
  7. package/dist/__tests__/events.test.js.map +1 -1
  8. package/dist/__tests__/functions.test.js +1 -3
  9. package/dist/__tests__/functions.test.js.map +1 -1
  10. package/dist/__tests__/lazy.test.js +6 -6
  11. package/dist/__tests__/lazy.test.js.map +1 -1
  12. package/dist/__tests__/properties.test.js +26 -0
  13. package/dist/__tests__/properties.test.js.map +1 -1
  14. package/dist/__tests__/synced.test.js +5 -4
  15. package/dist/__tests__/synced.test.js.map +1 -1
  16. package/dist/component/lazy.js +1 -0
  17. package/dist/component/lazy.js.map +1 -1
  18. package/dist/create-class-decorator.js +1 -4
  19. package/dist/create-class-decorator.js.map +1 -1
  20. package/dist/events/command.d.ts +1 -0
  21. package/dist/events/command.d.ts.map +1 -1
  22. package/dist/events/command.js +12 -0
  23. package/dist/events/command.js.map +1 -1
  24. package/dist/events/index.d.ts +1 -1
  25. package/dist/events/index.d.ts.map +1 -1
  26. package/dist/events/index.js +1 -1
  27. package/dist/events/index.js.map +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/properties/function-prop.d.ts.map +1 -1
  33. package/dist/properties/function-prop.js +4 -0
  34. package/dist/properties/function-prop.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/__tests__/events.test.ts +98 -1
  37. package/src/__tests__/properties.test.ts +28 -0
  38. package/src/events/command.ts +14 -0
  39. package/src/events/index.ts +1 -1
  40. package/src/index.ts +1 -1
  41. package/src/properties/function-prop.ts +8 -0
  42. 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 ──────────────────────────────────────────────────────────────────
@@ -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
+ }
@@ -1,3 +1,3 @@
1
- export { type Command, createCommand } from "./command";
1
+ export { Command, createCommand } from "./command";
2
2
  export { Emit } from "./emit";
3
3
  export { OnCommand } from "./on-command";
package/src/index.ts CHANGED
@@ -34,7 +34,7 @@ export {
34
34
  Ref,
35
35
  createRef,
36
36
  } from "./properties";
37
- export { type Command, createCommand, Emit, OnCommand } from "./events";
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);
package/tsconfig.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "extends": "../../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
- "rootDir": "./src"
5
+ "rootDir": "./src",
6
+ "types": ["node"]
6
7
  },
7
8
  "include": ["src"]
8
9
  }