@praxisjs/decorators 0.1.0 → 0.2.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @praxisjs/decorators
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f48dbc4: Introduce WithHistory<T, K> utility type for better TypeScript inference when using the @History decorator, and fix performance issues in the history() primitive.
8
+
9
+ Changes:
10
+
11
+ @praxisjs/decorators: Added WithHistory<T, K> type that maps a property key to its corresponding \*History accessor type, enabling proper type-checking on decorated classes.
12
+ @praxisjs/decorators: Simplified @History decorator internals — replaced verbose getOwnPropertyDescriptor lookups with direct property access (this[propertyKey]), reducing complexity.
13
+ @praxisjs/core: Fixed history() to use peek() when reading \_past and \_current inside the tracking effect, preventing unnecessary re-runs caused by reactive reads during history recording.
14
+ @praxisjs/core: Added an \_initialized guard so the first value is captured without pushing an empty entry into the past stack.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [f48dbc4]
19
+ - @praxisjs/core@0.2.0
20
+
3
21
  ## 0.1.0
4
22
 
5
23
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Component, Memoize, Lazy, Virtual } from "./component";
2
2
  export { Memo, Bind, Log, Once, Retry, Debounce, Throttle, When, Watch, type WatchVal, type WatchVals, } from "./functions";
3
- export { Prop, State, Persisted, Slot, initSlots, History } from "./properties";
3
+ export { Prop, State, Persisted, Slot, initSlots, History, type WithHistory } from "./properties";
4
4
  export { type Command, createCommand, Emit, OnCommand } from "./events";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,KAAK,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,GAGN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAgB,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,GAGN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAClG,OAAO,EAAgB,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
@@ -1,2 +1,4 @@
1
+ import { type HistoryElement } from "@praxisjs/core";
2
+ export type WithHistory<T, K extends keyof T> = Record<`${string & K}History`, HistoryElement<T[K]>>;
1
3
  export declare function History(limit?: number): (target: object, propertyKey: string) => void;
2
4
  //# sourceMappingURL=history.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAEA,wBAAgB,OAAO,CAAC,KAAK,SAAK,IACf,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,IAAI,CA0D5D"}
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,gBAAgB,CAAC;AAE9D,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAErG,wBAAgB,OAAO,CAAC,KAAK,SAAK,IACf,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,IAAI,CAkC5D"}
@@ -3,15 +3,10 @@ export function History(limit = 50) {
3
3
  return function (target, propertyKey) {
4
4
  const historyKey = `${propertyKey}History`;
5
5
  const histories = new WeakMap();
6
- const originalDescriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
7
6
  Object.defineProperty(target, historyKey, {
8
7
  get() {
9
8
  if (!histories.has(this)) {
10
- const source = () => {
11
- const desc = Object.getOwnPropertyDescriptor(this, propertyKey) ??
12
- Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), propertyKey);
13
- return desc?.get?.call(this);
14
- };
9
+ const source = () => this[propertyKey];
15
10
  const h = history(source, limit);
16
11
  const originalUndo = () => { h.undo(); };
17
12
  const originalRedo = () => { h.redo(); };
@@ -20,12 +15,11 @@ export function History(limit = 50) {
20
15
  if (prev === undefined)
21
16
  return;
22
17
  originalUndo();
23
- (Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), propertyKey) ?? originalDescriptor)?.set?.call(this, prev);
18
+ this[propertyKey] = prev;
24
19
  };
25
20
  h.redo = () => {
26
21
  originalRedo();
27
- const next = h.current();
28
- (Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), propertyKey) ?? originalDescriptor)?.set?.call(this, next);
22
+ this[propertyKey] = h.current();
29
23
  };
30
24
  histories.set(this, h);
31
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9D,MAAM,UAAU,OAAO,CAAC,KAAK,GAAG,EAAE;IAChC,OAAO,UAAU,MAAc,EAAE,WAAmB;QAClD,MAAM,UAAU,GAAG,GAAG,WAAW,SAAS,CA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C,CAAC;oBACzC,MAAM,YAAY,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;oBAEzC,CAAC,CAAC,IAAI,GAAG,GAAG,EAAE;wBACZ,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;wBAC/C,IAAI,IAAI,KAAK,SAAS;4BAAE,OAAO;wBAC/B,YAAY,EAAE,CAAC;wBACf,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;oBAC3B,CAAC,CAAC;oBAEF,CAAC,CAAC,IAAI,GAAG,GAAG,EAAE;wBACZ,YAAY,EAAE,CAAC;wBACf,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;oBAClC,CAAC,CAAC;oBAEF,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzB,CAAC;gBACD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAA4B,CAAC;YACxD,CAAC;YACD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -2,5 +2,5 @@ export { Prop } from "./prop";
2
2
  export { State } from "./state";
3
3
  export { Persisted } from "./persisted";
4
4
  export { Slot, initSlots } from "./slot";
5
- export { History } from "./history";
5
+ export { History, type WithHistory } from "./history";
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/decorators",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "typescript": "^5.9.3"
16
16
  },
17
17
  "dependencies": {
18
- "@praxisjs/core": "0.1.0",
18
+ "@praxisjs/core": "0.2.0",
19
19
  "@praxisjs/jsx": "0.1.0",
20
20
  "@praxisjs/shared": "0.1.0"
21
21
  },
package/src/index.ts CHANGED
@@ -12,5 +12,5 @@ export {
12
12
  type WatchVal,
13
13
  type WatchVals,
14
14
  } from "./functions";
15
- export { Prop, State, Persisted, Slot, initSlots, History } from "./properties";
15
+ export { Prop, State, Persisted, Slot, initSlots, History, type WithHistory } from "./properties";
16
16
  export { type Command, createCommand, Emit, OnCommand } from "./events";
@@ -1,27 +1,16 @@
1
1
  import { type HistoryElement, history } from "@praxisjs/core";
2
2
 
3
+ export type WithHistory<T, K extends keyof T> = Record<`${string & K}History`, HistoryElement<T[K]>>;
4
+
3
5
  export function History(limit = 50) {
4
6
  return function (target: object, propertyKey: string): void {
5
7
  const historyKey = `${propertyKey}History`;
6
8
  const histories = new WeakMap<object, HistoryElement<unknown>>();
7
9
 
8
- const originalDescriptor = Object.getOwnPropertyDescriptor(
9
- target,
10
- propertyKey,
11
- );
12
-
13
10
  Object.defineProperty(target, historyKey, {
14
- get(this: object): HistoryElement<unknown> {
11
+ get(this: Record<string, unknown>): HistoryElement<unknown> {
15
12
  if (!histories.has(this)) {
16
- const source = () => {
17
- const desc =
18
- Object.getOwnPropertyDescriptor(this, propertyKey) ??
19
- Object.getOwnPropertyDescriptor(
20
- Object.getPrototypeOf(this),
21
- propertyKey,
22
- );
23
- return desc?.get?.call(this) as unknown;
24
- };
13
+ const source = () => this[propertyKey];
25
14
 
26
15
  const h = history(source as () => unknown, limit);
27
16
 
@@ -32,23 +21,12 @@ export function History(limit = 50) {
32
21
  const prev = h.values()[h.values().length - 2];
33
22
  if (prev === undefined) return;
34
23
  originalUndo();
35
- (
36
- Object.getOwnPropertyDescriptor(
37
- Object.getPrototypeOf(this),
38
- propertyKey,
39
- ) ?? originalDescriptor
40
- )?.set?.call(this, prev);
24
+ this[propertyKey] = prev;
41
25
  };
42
26
 
43
27
  h.redo = () => {
44
28
  originalRedo();
45
- const next = h.current();
46
- (
47
- Object.getOwnPropertyDescriptor(
48
- Object.getPrototypeOf(this),
49
- propertyKey,
50
- ) ?? originalDescriptor
51
- )?.set?.call(this, next);
29
+ this[propertyKey] = h.current();
52
30
  };
53
31
 
54
32
  histories.set(this, h);
@@ -2,4 +2,4 @@ export { Prop } from "./prop";
2
2
  export { State } from "./state";
3
3
  export { Persisted } from "./persisted";
4
4
  export { Slot, initSlots } from "./slot";
5
- export { History } from "./history";
5
+ export { History, type WithHistory } from "./history";