@praxisjs/store 0.1.1 → 0.2.1

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,30 @@
1
1
  # @praxisjs/store
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [f52354d]
8
+ - @praxisjs/core@0.4.0
9
+
10
+ ## 0.2.0
11
+
12
+ ### Minor Changes
13
+
14
+ - bb0d4f8: **Refactor decorator system and component architecture across PraxisJS packages**
15
+
16
+ - Replaced legacy decorator signatures (`constructor`, `target`, `propertyKey`, method descriptor) with the standard TC39 decorator context API (`ClassDecoratorContext`, `ClassFieldDecoratorContext`, `ClassMethodDecoratorContext`) across `@praxisjs/decorators`, `@praxisjs/store`, `@praxisjs/concurrent`, `@praxisjs/router`, `@praxisjs/motion`, `@praxisjs/di`, and `@praxisjs/fsm`.
17
+ - Introduced `StatefulComponent` and `StatelessComponent` as the new base classes, replacing the deprecated `BaseComponent`/`Function Component` pattern, across `@praxisjs/core`, `@praxisjs/runtime`, `@praxisjs/devtools`, and templates.
18
+ - Implemented core rendering functionality in `@praxisjs/runtime` (`mountChildren`, `mountComponent`, reactive scope management) and removed the deprecated `renderer.ts`.
19
+ - Refactored `@praxisjs/jsx` to delegate rendering to `@praxisjs/runtime` and improved type safety with `flattenChildren` and `isComponent` utilities.
20
+ - Updated internal module structure with new `internal` exports in `package.json` files for shared utilities and types.
21
+ - Removed `experimentalDecorators`/`emitDecoratorMetadata` from `tsconfig.json` in favor of native decorator support.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [bb0d4f8]
26
+ - @praxisjs/core@0.3.0
27
+
3
28
  ## 0.1.1
4
29
 
5
30
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"create-store.d.ts","sourceRoot":"","sources":["../src/create-store.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,WA4D5B"}
1
+ {"version":3,"file":"create-store.d.ts","sourceRoot":"","sources":["../src/create-store.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,WAgE5B"}
@@ -1,4 +1,4 @@
1
- import { signal, effect } from "@praxisjs/core";
1
+ import { signal, effect } from "@praxisjs/core/internal";
2
2
  export function createStore(definition) {
3
3
  const initialState = {};
4
4
  const methods = {};
@@ -50,7 +50,9 @@ export function createStore(definition) {
50
50
  return s;
51
51
  }
52
52
  function subscribe(fn) {
53
- return effect(() => { fn(getState()); });
53
+ return effect(() => {
54
+ fn(getState());
55
+ });
54
56
  }
55
57
  function reset() {
56
58
  for (const [k, v] of Object.entries(initialState))
@@ -1 +1 @@
1
- {"version":3,"file":"create-store.js","sourceRoot":"","sources":["../src/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,UAAU,WAAW,CACzB,UAA2B;IAE3B,MAAM,YAAY,GAA4B,EAAE,CAAC;IACjD,MAAM,OAAO,GAAoD,EAAE,CAAC;IAEpE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,IAAI,OAAO,KAAK,KAAK,UAAU;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAwC,CAAC;;YACpF,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACjC,CAAC;IAED,MAAM,OAAO,GAA8C,EAAE,CAAC;IAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,C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constructor: T) => T;
2
- export declare function UseStore(StoreConstructor: new () => unknown): (target: object, propertyKey: string | symbol) => void;
1
+ export declare function Store(): (value: new (...args: unknown[]) => unknown, _context: ClassDecoratorContext) => void;
2
+ export declare function UseStore(StoreConstructor: new () => unknown): (_value: undefined, context: ClassFieldDecoratorContext) => void;
3
3
  //# sourceMappingURL=decorators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,KACF,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,aAAa,CAAC,KAAG,CAAC,CAInF;AAED,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,UAAU,OAAO,IAGzC,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,KAAG,IAAI,CAkBrE"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,KACF,OAAO,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,UAAU,qBAAqB,KAAG,IAAI,CAGpG;AAED,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,UAAU,OAAO,IACzC,QAAQ,SAAS,EAAE,SAAS,0BAA0B,KAAG,IAAI,CAsB/E"}
@@ -1,26 +1,27 @@
1
1
  const storeRegistry = new Map();
2
2
  export function Store() {
3
- return function (constructor) {
4
- storeRegistry.set(constructor, null);
5
- return constructor;
3
+ return function (value, _context) {
4
+ storeRegistry.set(value, null);
6
5
  };
7
6
  }
8
7
  export function UseStore(StoreConstructor) {
9
- const cache = new WeakMap();
10
- return function (target, propertyKey) {
11
- Object.defineProperty(target, propertyKey, {
12
- get() {
13
- if (!cache.has(this)) {
14
- if (!storeRegistry.has(StoreConstructor) ||
15
- storeRegistry.get(StoreConstructor) === null) {
16
- storeRegistry.set(StoreConstructor, new StoreConstructor());
8
+ return function (_value, context) {
9
+ const cache = new WeakMap();
10
+ context.addInitializer(function () {
11
+ Object.defineProperty(this, context.name, {
12
+ get() {
13
+ if (!cache.has(this)) {
14
+ if (!storeRegistry.has(StoreConstructor) ||
15
+ storeRegistry.get(StoreConstructor) === null) {
16
+ storeRegistry.set(StoreConstructor, new StoreConstructor());
17
+ }
18
+ cache.set(this, storeRegistry.get(StoreConstructor));
17
19
  }
18
- cache.set(this, storeRegistry.get(StoreConstructor));
19
- }
20
- return cache.get(this);
21
- },
22
- enumerable: true,
23
- configurable: true,
20
+ return cache.get(this);
21
+ },
22
+ enumerable: true,
23
+ configurable: true,
24
+ });
24
25
  });
25
26
  };
26
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,IAAI,GAAG,EAAgD,CAAC;AAE9E,MAAM,UAAU,KAAK;IACnB,OAAO,UAAyD,WAAc;QAC5E,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,gBAAmC;IAC1D,MAAM,KAAK,GAAG,IAAI,OAAO,EAAmB,CAAC;IAE7C,OAAO,UAAU,MAAc,EAAE,WAA4B;QAC3D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YACzC,GAAG;gBACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACrB,IACE,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC;wBACpC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAC5C,CAAC;wBACD,aAAa,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAC;oBAC9D,CAAC;oBACD,KAAK,CAAC,GA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,IAAI;gBAChB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/store",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "typescript": "^5.9.3"
15
15
  },
16
16
  "dependencies": {
17
- "@praxisjs/core": "0.2.0"
17
+ "@praxisjs/core": "0.4.0"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc",
@@ -1,4 +1,4 @@
1
- import { signal, effect } from "@praxisjs/core";
1
+ import { signal, effect } from "@praxisjs/core/internal";
2
2
 
3
3
  export function createStore<T extends Record<string, unknown>>(
4
4
  definition: T & ThisType<T>,
@@ -7,7 +7,8 @@ export function createStore<T extends Record<string, unknown>>(
7
7
  const methods: Record<string, (...args: unknown[]) => unknown> = {};
8
8
 
9
9
  for (const [key, value] of Object.entries(definition)) {
10
- if (typeof value === "function") methods[key] = value as (...args: unknown[]) => unknown;
10
+ if (typeof value === "function")
11
+ methods[key] = value as (...args: unknown[]) => unknown;
11
12
  else initialState[key] = value;
12
13
  }
13
14
 
@@ -20,7 +21,8 @@ export function createStore<T extends Record<string, unknown>>(
20
21
  get(_t, key: string | symbol) {
21
22
  if (typeof key !== "string") return undefined;
22
23
  if (key in methods)
23
- return (...args: unknown[]): unknown => methods[key].call(store, ...args);
24
+ return (...args: unknown[]): unknown =>
25
+ methods[key].call(store, ...args);
24
26
  if (key === "$subscribe") return subscribe;
25
27
  if (key === "$reset") return reset;
26
28
  if (key === "$patch") return patch;
@@ -47,7 +49,9 @@ export function createStore<T extends Record<string, unknown>>(
47
49
  }
48
50
 
49
51
  function subscribe(fn: (state: Record<string, unknown>) => void): () => void {
50
- return effect(() => { fn(getState()); });
52
+ return effect(() => {
53
+ fn(getState());
54
+ });
51
55
  }
52
56
 
53
57
  function reset(): void {
package/src/decorators.ts CHANGED
@@ -1,31 +1,32 @@
1
1
  const storeRegistry = new Map<new (...args: unknown[]) => unknown, unknown>();
2
2
 
3
3
  export function Store() {
4
- return function <T extends new (...args: unknown[]) => unknown>(constructor: T): T {
5
- storeRegistry.set(constructor, null);
6
- return constructor;
4
+ return function (value: new (...args: unknown[]) => unknown, _context: ClassDecoratorContext): void {
5
+ storeRegistry.set(value, null);
7
6
  };
8
7
  }
9
8
 
10
9
  export function UseStore(StoreConstructor: new () => unknown) {
11
- const cache = new WeakMap<object, unknown>();
10
+ return function (_value: undefined, context: ClassFieldDecoratorContext): void {
11
+ const cache = new WeakMap<object, unknown>();
12
12
 
13
- return function (target: object, propertyKey: string | symbol): void {
14
- Object.defineProperty(target, propertyKey, {
15
- get(this: object): unknown {
16
- if (!cache.has(this)) {
17
- if (
18
- !storeRegistry.has(StoreConstructor) ||
19
- storeRegistry.get(StoreConstructor) === null
20
- ) {
21
- storeRegistry.set(StoreConstructor, new StoreConstructor());
13
+ context.addInitializer(function (this: unknown) {
14
+ Object.defineProperty(this, context.name, {
15
+ get(this: object): unknown {
16
+ if (!cache.has(this)) {
17
+ if (
18
+ !storeRegistry.has(StoreConstructor) ||
19
+ storeRegistry.get(StoreConstructor) === null
20
+ ) {
21
+ storeRegistry.set(StoreConstructor, new StoreConstructor());
22
+ }
23
+ cache.set(this, storeRegistry.get(StoreConstructor));
22
24
  }
23
- cache.set(this, storeRegistry.get(StoreConstructor));
24
- }
25
- return cache.get(this);
26
- },
27
- enumerable: true,
28
- configurable: true,
25
+ return cache.get(this);
26
+ },
27
+ enumerable: true,
28
+ configurable: true,
29
+ });
29
30
  });
30
31
  };
31
32
  }