@praxisjs/store 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 +25 -0
- package/dist/create-store.d.ts.map +1 -1
- package/dist/create-store.js +4 -2
- package/dist/create-store.js.map +1 -1
- package/dist/decorators.d.ts +2 -2
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +18 -17
- package/dist/decorators.js.map +1 -1
- package/package.json +2 -2
- package/src/create-store.ts +8 -4
- package/src/decorators.ts +20 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @praxisjs/store
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bb0d4f8: **Refactor decorator system and component architecture across PraxisJS packages**
|
|
8
|
+
|
|
9
|
+
- 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`.
|
|
10
|
+
- 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.
|
|
11
|
+
- Implemented core rendering functionality in `@praxisjs/runtime` (`mountChildren`, `mountComponent`, reactive scope management) and removed the deprecated `renderer.ts`.
|
|
12
|
+
- Refactored `@praxisjs/jsx` to delegate rendering to `@praxisjs/runtime` and improved type safety with `flattenChildren` and `isComponent` utilities.
|
|
13
|
+
- Updated internal module structure with new `internal` exports in `package.json` files for shared utilities and types.
|
|
14
|
+
- Removed `experimentalDecorators`/`emitDecoratorMetadata` from `tsconfig.json` in favor of native decorator support.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [bb0d4f8]
|
|
19
|
+
- @praxisjs/core@0.3.0
|
|
20
|
+
|
|
21
|
+
## 0.1.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [f48dbc4]
|
|
26
|
+
- @praxisjs/core@0.2.0
|
|
27
|
+
|
|
3
28
|
## 0.1.0
|
|
4
29
|
|
|
5
30
|
### Minor 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,
|
|
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"}
|
package/dist/create-store.js
CHANGED
|
@@ -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(() => {
|
|
53
|
+
return effect(() => {
|
|
54
|
+
fn(getState());
|
|
55
|
+
});
|
|
54
56
|
}
|
|
55
57
|
function reset() {
|
|
56
58
|
for (const [k, v] of Object.entries(initialState))
|
package/dist/create-store.js.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"create-store.js","sourceRoot":"","sources":["../src/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEzD,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;YAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAwC,CAAC;;YACrD,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,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAO,EAAE;QAC/B,GAAG,CAAC,EAAE,EAAE,GAAoB;YAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAC;YAC9C,IAAI,GAAG,IAAI,OAAO;gBAChB,OAAO,CAAC,GAAG,IAAe,EAAW,EAAE,CACrC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;YACtC,IAAI,GAAG,KAAK,YAAY;gBAAE,OAAO,SAAS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AAM,CAAC,OAAO,CAAC,YAAY,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,SAAS,KAAK,CAAC,OAAyC;QACtD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,OAAO;gBAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACrB,CAAC"}
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function Store():
|
|
2
|
-
export declare function UseStore(StoreConstructor: new () => unknown): (
|
|
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
|
package/dist/decorators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,KACF,
|
|
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"}
|
package/dist/decorators.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
const storeRegistry = new Map();
|
|
2
2
|
export function Store() {
|
|
3
|
-
return function (
|
|
4
|
-
storeRegistry.set(
|
|
5
|
-
return constructor;
|
|
3
|
+
return function (value, _context) {
|
|
4
|
+
storeRegistry.set(value, null);
|
|
6
5
|
};
|
|
7
6
|
}
|
|
8
7
|
export function UseStore(StoreConstructor) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!
|
|
15
|
-
storeRegistry.
|
|
16
|
-
|
|
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.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
configurable: true,
|
|
20
|
+
return cache.get(this);
|
|
21
|
+
},
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
});
|
|
24
25
|
});
|
|
25
26
|
};
|
|
26
27
|
}
|
package/dist/decorators.js.map
CHANGED
|
@@ -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,
|
|
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,UAAU,KAA0C,EAAE,QAA+B;QAC1F,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,gBAAmC;IAC1D,OAAO,UAAU,MAAiB,EAAE,OAAmC;QACrE,MAAM,KAAK,GAAG,IAAI,OAAO,EAAmB,CAAC;QAE7C,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;gBACxC,GAAG;oBACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;wBACrB,IACE,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC;4BACpC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAC5C,CAAC;4BACD,aAAa,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAC;wBAC9D,CAAC;wBACD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;oBACvD,CAAC;oBACD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACzB,CAAC;gBACD,UAAU,EAAE,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.
|
|
3
|
+
"version": "0.2.0",
|
|
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.
|
|
17
|
+
"@praxisjs/core": "0.3.0"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc",
|
package/src/create-store.ts
CHANGED
|
@@ -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")
|
|
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 =>
|
|
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(() => {
|
|
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
|
|
5
|
-
storeRegistry.set(
|
|
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
|
-
|
|
10
|
+
return function (_value: undefined, context: ClassFieldDecoratorContext): void {
|
|
11
|
+
const cache = new WeakMap<object, unknown>();
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
configurable: true,
|
|
25
|
+
return cache.get(this);
|
|
26
|
+
},
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
});
|
|
29
30
|
});
|
|
30
31
|
};
|
|
31
32
|
}
|