@akanjs/store 0.9.48 → 0.9.49

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.
@@ -0,0 +1,65 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var storeInfo_exports = {};
19
+ __export(storeInfo_exports, {
20
+ storeInfo: () => storeInfo
21
+ });
22
+ module.exports = __toCommonJS(storeInfo_exports);
23
+ var import_storeDecorators = require("./storeDecorators");
24
+ const storeInfo = {
25
+ store: /* @__PURE__ */ new Map(),
26
+ storeRefNameMap: /* @__PURE__ */ new Map(),
27
+ setRefNameTemp(refName, store) {
28
+ Reflect.defineMetadata("akan:storeRefName", refName, store.prototype);
29
+ },
30
+ getRefNameTemp(store) {
31
+ const refName = Reflect.getMetadata("akan:storeRefName", store.prototype);
32
+ if (!refName)
33
+ throw new Error(`No ref name for store: ${store}`);
34
+ return refName;
35
+ },
36
+ setState(storeRef, applyState) {
37
+ const state = storeInfo.getState(storeRef);
38
+ Object.assign(state, applyState);
39
+ Reflect.defineMetadata("akan:store:state", state, storeRef.prototype);
40
+ },
41
+ getState(storeRef) {
42
+ const state = Reflect.getMetadata("akan:store:state", storeRef.prototype);
43
+ return state ?? {};
44
+ },
45
+ applyAction(storeRef) {
46
+ const actionKeys = Object.getOwnPropertyNames(storeRef.prototype).filter((key) => key !== "constructor");
47
+ const action = storeInfo.getAction(storeRef);
48
+ const applyAction = Object.fromEntries(actionKeys.map((key) => [key, storeRef.prototype[key]]));
49
+ Object.assign(action, applyAction);
50
+ Reflect.defineMetadata("akan:store:action", action, storeRef.prototype);
51
+ },
52
+ getAction(storeRef) {
53
+ const action = Reflect.getMetadata("akan:store:action", storeRef.prototype);
54
+ return action ?? {};
55
+ },
56
+ register(refName, storeRef) {
57
+ storeInfo.setRefNameTemp(refName, storeRef);
58
+ storeInfo.applyAction(storeRef);
59
+ storeInfo.store.set(refName, storeRef);
60
+ return storeRef;
61
+ },
62
+ buildStore(signals) {
63
+ (0, import_storeDecorators.makeStore)(import_storeDecorators.baseSt, signals);
64
+ }
65
+ };
package/esm/src/baseSt.js CHANGED
@@ -1,18 +1,8 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
10
- return result;
11
- };
12
1
  import { defaultPageState } from "@akanjs/client";
13
2
  import { Responsive, responsiveWidths } from "@akanjs/constant";
14
3
  import { defaultAccount, roleTypes } from "@akanjs/signal";
15
- import { baseSt, makeStore, scalarStateOf, Store } from "./storeDecorators";
4
+ import { baseSt, store } from "./storeDecorators";
5
+ import { storeInfo } from "./storeInfo";
16
6
  const defaultMessage = {
17
7
  type: "info",
18
8
  content: "",
@@ -20,7 +10,7 @@ const defaultMessage = {
20
10
  // seconds
21
11
  key: Math.random().toString(36).slice(2, 15)
22
12
  };
23
- let RootStore = class extends scalarStateOf("root", {
13
+ class RootStore extends store("root", {
24
14
  csrLoaded: false,
25
15
  path: "/",
26
16
  pathname: typeof window !== "undefined" ? window.location.pathname : "/",
@@ -68,14 +58,11 @@ let RootStore = class extends scalarStateOf("root", {
68
58
  const { messages } = this.get();
69
59
  this.set({ messages: messages.filter((m) => m.key !== key) });
70
60
  }
71
- };
72
- RootStore = __decorateClass([
73
- Store({ name: "root" })
74
- ], RootStore);
75
- const store = RootStore;
76
- const st = makeStore(baseSt, store, { library: true });
61
+ }
62
+ const base = storeInfo.register("base", RootStore);
63
+ const st = baseSt;
77
64
  export {
78
65
  RootStore,
79
- st,
80
- store
66
+ base,
67
+ st
81
68
  };
package/esm/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./storeDecorators";
3
3
  export * from "./baseSt";
4
+ export * from "./storeInfo";