@figliolia/galena 2.3.5 → 3.0.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 (144) hide show
  1. package/README.md +172 -476
  2. package/dist/Galena.cjs +102 -0
  3. package/dist/Galena.d.cts +80 -0
  4. package/dist/Galena.d.cts.map +1 -0
  5. package/dist/Galena.d.mts +80 -0
  6. package/dist/Galena.d.mts.map +1 -0
  7. package/dist/Galena.mjs +103 -0
  8. package/dist/Galena.mjs.map +1 -0
  9. package/dist/GalenaProvider.cjs +50 -0
  10. package/dist/GalenaProvider.d.cts +35 -0
  11. package/dist/GalenaProvider.d.cts.map +1 -0
  12. package/dist/GalenaProvider.d.mts +35 -0
  13. package/dist/GalenaProvider.d.mts.map +1 -0
  14. package/dist/GalenaProvider.mjs +52 -0
  15. package/dist/GalenaProvider.mjs.map +1 -0
  16. package/dist/Logger.cjs +46 -0
  17. package/dist/Logger.d.cts +35 -0
  18. package/dist/Logger.d.cts.map +1 -0
  19. package/dist/Logger.d.mts +35 -0
  20. package/dist/Logger.d.mts.map +1 -0
  21. package/dist/Logger.mjs +48 -0
  22. package/dist/Logger.mjs.map +1 -0
  23. package/dist/Middleware.cjs +62 -0
  24. package/dist/Middleware.d.cts +65 -0
  25. package/dist/Middleware.d.cts.map +1 -0
  26. package/dist/Middleware.d.mts +65 -0
  27. package/dist/Middleware.d.mts.map +1 -0
  28. package/dist/Middleware.mjs +64 -0
  29. package/dist/Middleware.mjs.map +1 -0
  30. package/dist/Profiler.cjs +41 -0
  31. package/dist/Profiler.d.cts +31 -0
  32. package/dist/Profiler.d.cts.map +1 -0
  33. package/dist/Profiler.d.mts +31 -0
  34. package/dist/Profiler.d.mts.map +1 -0
  35. package/dist/Profiler.mjs +43 -0
  36. package/dist/Profiler.mjs.map +1 -0
  37. package/dist/State.cjs +147 -0
  38. package/dist/State.d.cts +114 -0
  39. package/dist/State.d.cts.map +1 -0
  40. package/dist/State.d.mts +114 -0
  41. package/dist/State.d.mts.map +1 -0
  42. package/dist/State.mjs +148 -0
  43. package/dist/State.mjs.map +1 -0
  44. package/dist/commonHooks.cjs +17 -0
  45. package/dist/commonHooks.mjs +18 -0
  46. package/dist/commonHooks.mjs.map +1 -0
  47. package/dist/connect-multi.cjs +42 -0
  48. package/dist/connect-multi.d.cts +10 -0
  49. package/dist/connect-multi.d.cts.map +1 -0
  50. package/dist/connect-multi.d.mts +10 -0
  51. package/dist/connect-multi.d.mts.map +1 -0
  52. package/dist/connect-multi.mjs +44 -0
  53. package/dist/connect-multi.mjs.map +1 -0
  54. package/dist/connect.cjs +41 -0
  55. package/dist/connect.d.cts +9 -0
  56. package/dist/connect.d.cts.map +1 -0
  57. package/dist/connect.d.mts +9 -0
  58. package/dist/connect.d.mts.map +1 -0
  59. package/dist/connect.mjs +43 -0
  60. package/dist/connect.mjs.map +1 -0
  61. package/dist/createUseState.cjs +47 -0
  62. package/dist/createUseState.d.cts +46 -0
  63. package/dist/createUseState.d.cts.map +1 -0
  64. package/dist/createUseState.d.mts +46 -0
  65. package/dist/createUseState.d.mts.map +1 -0
  66. package/dist/createUseState.mjs +49 -0
  67. package/dist/createUseState.mjs.map +1 -0
  68. package/dist/index.cjs +23 -0
  69. package/dist/index.d.cts +12 -0
  70. package/dist/index.d.mts +12 -0
  71. package/dist/index.mjs +11 -0
  72. package/dist/types.d.cts +23 -0
  73. package/dist/types.d.cts.map +1 -0
  74. package/dist/types.d.mts +23 -0
  75. package/dist/types.d.mts.map +1 -0
  76. package/dist/useState.cjs +45 -0
  77. package/dist/useState.d.cts +43 -0
  78. package/dist/useState.d.cts.map +1 -0
  79. package/dist/useState.d.mts +43 -0
  80. package/dist/useState.d.mts.map +1 -0
  81. package/dist/useState.mjs +47 -0
  82. package/dist/useState.mjs.map +1 -0
  83. package/media/Logging.png +0 -0
  84. package/media/Profiling.png +0 -0
  85. package/package.json +38 -59
  86. package/src/Galena.ts +120 -0
  87. package/src/{Middlewares/Logger.ts → Logger.ts} +15 -14
  88. package/src/Middleware.ts +62 -0
  89. package/src/Profiler.ts +53 -0
  90. package/src/State.ts +167 -0
  91. package/src/index.ts +6 -3
  92. package/src/types.ts +28 -0
  93. package/dist/cjs/Galena/Galena.js +0 -223
  94. package/dist/cjs/Galena/Guards.js +0 -40
  95. package/dist/cjs/Galena/Scheduler.js +0 -84
  96. package/dist/cjs/Galena/State.js +0 -314
  97. package/dist/cjs/Galena/index.js +0 -22
  98. package/dist/cjs/Galena/types.js +0 -9
  99. package/dist/cjs/Middleware/Middleware.js +0 -46
  100. package/dist/cjs/Middleware/index.js +0 -20
  101. package/dist/cjs/Middleware/types.js +0 -8
  102. package/dist/cjs/Middlewares/Logger.js +0 -51
  103. package/dist/cjs/Middlewares/Profiler.js +0 -38
  104. package/dist/cjs/Middlewares/index.js +0 -7
  105. package/dist/cjs/index.js +0 -19
  106. package/dist/cjs/package.json +0 -3
  107. package/dist/mjs/Galena/Galena.js +0 -218
  108. package/dist/mjs/Galena/Guards.js +0 -36
  109. package/dist/mjs/Galena/Scheduler.js +0 -79
  110. package/dist/mjs/Galena/State.js +0 -313
  111. package/dist/mjs/Galena/index.js +0 -3
  112. package/dist/mjs/Galena/types.js +0 -6
  113. package/dist/mjs/Middleware/Middleware.js +0 -42
  114. package/dist/mjs/Middleware/index.js +0 -2
  115. package/dist/mjs/Middleware/types.js +0 -5
  116. package/dist/mjs/Middlewares/Logger.js +0 -44
  117. package/dist/mjs/Middlewares/Profiler.js +0 -35
  118. package/dist/mjs/Middlewares/index.js +0 -2
  119. package/dist/mjs/index.js +0 -3
  120. package/dist/mjs/package.json +0 -4
  121. package/dist/types/Galena/Galena.d.ts +0 -160
  122. package/dist/types/Galena/Guards.d.ts +0 -29
  123. package/dist/types/Galena/Scheduler.d.ts +0 -51
  124. package/dist/types/Galena/State.d.ts +0 -235
  125. package/dist/types/Galena/index.d.ts +0 -3
  126. package/dist/types/Galena/types.d.ts +0 -13
  127. package/dist/types/Middleware/Middleware.d.ts +0 -43
  128. package/dist/types/Middleware/index.d.ts +0 -2
  129. package/dist/types/Middleware/types.d.ts +0 -4
  130. package/dist/types/Middlewares/Logger.d.ts +0 -27
  131. package/dist/types/Middlewares/Profiler.d.ts +0 -22
  132. package/dist/types/Middlewares/index.d.ts +0 -2
  133. package/dist/types/index.d.ts +0 -3
  134. package/src/Galena/Galena.ts +0 -252
  135. package/src/Galena/Guards.ts +0 -49
  136. package/src/Galena/Scheduler.ts +0 -85
  137. package/src/Galena/State.ts +0 -344
  138. package/src/Galena/index.ts +0 -3
  139. package/src/Galena/types.ts +0 -18
  140. package/src/Middleware/Middleware.ts +0 -45
  141. package/src/Middleware/index.ts +0 -2
  142. package/src/Middleware/types.ts +0 -4
  143. package/src/Middlewares/Profiler.ts +0 -41
  144. package/src/Middlewares/index.ts +0 -2
@@ -0,0 +1,102 @@
1
+ let _figliolia_event_emitter = require("@figliolia/event-emitter");
2
+ //#region src/Galena.ts
3
+ /**
4
+ * Galena
5
+ *
6
+ * Galena is designed to house one or more units of `State`
7
+ * and exist as a pseudo global application state.
8
+ *
9
+ * By design, each of its `State` units have isolated reactivity
10
+ * that prevents entire state trees from updating when a single
11
+ * unit changes.
12
+ *
13
+ * This is dissimilar to redux-like models where downstream reconciliations
14
+ * will propagate everwhere a given store is read from. In galena, downstream
15
+ * reconciliations occur only for consumers of the slice of state that
16
+ * changed - making it safer to use with more frequent state changes.
17
+ *
18
+ * ```typescript
19
+ * import { Galena } from "@figliolia/galena";
20
+ *
21
+ * const AppState = new Galena({
22
+ * // your reactive instances
23
+ * }, ...middleware);
24
+ *
25
+ * // to retreive and work with an individual unit
26
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
27
+ *
28
+ * // to run a callback anytime a unit of state changes
29
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
30
+ * // do something with the `State` instance that updated
31
+ * });
32
+ * ```
33
+ */
34
+ var Galena = class {
35
+ Emitter = new _figliolia_event_emitter.EventEmitter();
36
+ constructor(state, ...middleware) {
37
+ this.state = state;
38
+ this.registerMiddleware(...middleware);
39
+ }
40
+ get(key) {
41
+ return this.state[key];
42
+ }
43
+ subscribe = (subscriber) => {
44
+ const ID = this.Emitter.on("change", subscriber);
45
+ const unsubscribers = [];
46
+ for (const key in this.state) {
47
+ const instance = this.state[key];
48
+ if (!instance) continue;
49
+ unsubscribers.push(instance.subscribe(() => this.emit({
50
+ state: this.state,
51
+ updated: instance
52
+ })));
53
+ }
54
+ return () => {
55
+ this.Emitter.off("change", ID);
56
+ while (unsubscribers.length) unsubscribers.pop?.()?.();
57
+ };
58
+ };
59
+ registerMiddleware(...middlewares) {
60
+ for (const key in this.state) this.state[key]?.registerMiddleware?.(...middlewares);
61
+ }
62
+ emit(event) {
63
+ this.Emitter.emit("change", event);
64
+ }
65
+ };
66
+ /**
67
+ * Create Galena
68
+ *
69
+ * Galena is designed to house one or more units of `State`
70
+ * and exist as a pseudo global application state.
71
+ *
72
+ * By design, each of its `State` units have isolated reactivity
73
+ * that prevents entire state trees from updating when a single
74
+ * unit changes.
75
+ *
76
+ * This is dissimilar to redux-like models where downstream reconciliations
77
+ * will propagate everwhere a given store is read from. In galena, downstream
78
+ * reconciliations occur only for consumers of the slice of state that
79
+ * changed - making it safer to use with more frequent state changes.
80
+ *
81
+ * ```typescript
82
+ * import { createGalena } from "@figliolia/galena";
83
+ *
84
+ * const AppState = createGalena({
85
+ * // your reactive instances
86
+ * }, ...middleware);
87
+ *
88
+ * // to retreive and work with an individual unit
89
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
90
+ *
91
+ * // to run a callback anytime a unit of state changes
92
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
93
+ * // do something with the `State` instance that updated
94
+ * });
95
+ * ```
96
+ */
97
+ const createGalena = (...args) => {
98
+ return new Galena(...args);
99
+ };
100
+ //#endregion
101
+ exports.Galena = Galena;
102
+ exports.createGalena = createGalena;
@@ -0,0 +1,80 @@
1
+ import { Middleware } from "./Middleware.cjs";
2
+ import { AppSubscriber, StateTypes } from "./types.cjs";
3
+ import { State } from "./State.cjs";
4
+
5
+ //#region src/Galena.d.ts
6
+ /**
7
+ * Galena
8
+ *
9
+ * Galena is designed to house one or more units of `State`
10
+ * and exist as a pseudo global application state.
11
+ *
12
+ * By design, each of its `State` units have isolated reactivity
13
+ * that prevents entire state trees from updating when a single
14
+ * unit changes.
15
+ *
16
+ * This is dissimilar to redux-like models where downstream reconciliations
17
+ * will propagate everwhere a given store is read from. In galena, downstream
18
+ * reconciliations occur only for consumers of the slice of state that
19
+ * changed - making it safer to use with more frequent state changes.
20
+ *
21
+ * ```typescript
22
+ * import { Galena } from "@figliolia/galena";
23
+ *
24
+ * const AppState = new Galena({
25
+ * // your reactive instances
26
+ * }, ...middleware);
27
+ *
28
+ * // to retreive and work with an individual unit
29
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
30
+ *
31
+ * // to run a callback anytime a unit of state changes
32
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
33
+ * // do something with the `State` instance that updated
34
+ * });
35
+ * ```
36
+ */
37
+ declare class Galena<T extends Record<string, State<any>>> {
38
+ readonly state: T;
39
+ private Emitter;
40
+ constructor(state: T, ...middleware: Middleware<StateTypes<T>>[]);
41
+ get<K extends Extract<keyof T, string>>(key: K): T[K];
42
+ subscribe: (subscriber: AppSubscriber<T>) => () => void;
43
+ registerMiddleware(...middlewares: Middleware<StateTypes<T>>[]): void;
44
+ private emit;
45
+ }
46
+ /**
47
+ * Create Galena
48
+ *
49
+ * Galena is designed to house one or more units of `State`
50
+ * and exist as a pseudo global application state.
51
+ *
52
+ * By design, each of its `State` units have isolated reactivity
53
+ * that prevents entire state trees from updating when a single
54
+ * unit changes.
55
+ *
56
+ * This is dissimilar to redux-like models where downstream reconciliations
57
+ * will propagate everwhere a given store is read from. In galena, downstream
58
+ * reconciliations occur only for consumers of the slice of state that
59
+ * changed - making it safer to use with more frequent state changes.
60
+ *
61
+ * ```typescript
62
+ * import { createGalena } from "@figliolia/galena";
63
+ *
64
+ * const AppState = createGalena({
65
+ * // your reactive instances
66
+ * }, ...middleware);
67
+ *
68
+ * // to retreive and work with an individual unit
69
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
70
+ *
71
+ * // to run a callback anytime a unit of state changes
72
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
73
+ * // do something with the `State` instance that updated
74
+ * });
75
+ * ```
76
+ */
77
+ declare const createGalena: <T extends Record<string, State<any>>>(...args: ConstructorParameters<typeof Galena<T>>) => Galena<T>;
78
+ //#endregion
79
+ export { Galena, createGalena };
80
+ //# sourceMappingURL=Galena.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Galena.d.cts","names":[],"sources":["../src/Galena.ts"],"mappings":";;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,MAAA,WAAiB,MAAA,SAAe,KAAA;EAAA,SAGzB,KAAA,EAAO,CAAA;EAAA,QAFjB,OAAA;cAEU,KAAA,EAAO,CAAA,KACpB,UAAA,EAAY,UAAA,CAAW,UAAA,CAAW,CAAA;EAKhC,GAAA,WAAc,OAAA,OAAc,CAAA,UAAA,CAAY,GAAA,EAAK,CAAA,GAAC,CAAA,CAAA,CAAA;EAI9C,SAAA,GAAa,UAAA,EAAY,aAAA,CAAc,CAAA;EAsBvC,kBAAA,CAAA,GAAsB,WAAA,EAAa,UAAA,CAAW,UAAA,CAAW,CAAA;EAAA,QAMxD,IAAA;AAAA;;;;;;;;;;;;;;;;;;AAsCV;;;;;;;;;;;;;;cAAa,YAAA,aAA0B,MAAA,SAAe,KAAA,WACjD,IAAA,EAAM,qBAAA,QAA6B,MAAA,CAAO,CAAA,OAAG,MAAA,CAAA,CAAA"}
@@ -0,0 +1,80 @@
1
+ import { Middleware } from "./Middleware.mjs";
2
+ import { AppSubscriber, StateTypes } from "./types.mjs";
3
+ import { State } from "./State.mjs";
4
+
5
+ //#region src/Galena.d.ts
6
+ /**
7
+ * Galena
8
+ *
9
+ * Galena is designed to house one or more units of `State`
10
+ * and exist as a pseudo global application state.
11
+ *
12
+ * By design, each of its `State` units have isolated reactivity
13
+ * that prevents entire state trees from updating when a single
14
+ * unit changes.
15
+ *
16
+ * This is dissimilar to redux-like models where downstream reconciliations
17
+ * will propagate everwhere a given store is read from. In galena, downstream
18
+ * reconciliations occur only for consumers of the slice of state that
19
+ * changed - making it safer to use with more frequent state changes.
20
+ *
21
+ * ```typescript
22
+ * import { Galena } from "@figliolia/galena";
23
+ *
24
+ * const AppState = new Galena({
25
+ * // your reactive instances
26
+ * }, ...middleware);
27
+ *
28
+ * // to retreive and work with an individual unit
29
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
30
+ *
31
+ * // to run a callback anytime a unit of state changes
32
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
33
+ * // do something with the `State` instance that updated
34
+ * });
35
+ * ```
36
+ */
37
+ declare class Galena<T extends Record<string, State<any>>> {
38
+ readonly state: T;
39
+ private Emitter;
40
+ constructor(state: T, ...middleware: Middleware<StateTypes<T>>[]);
41
+ get<K extends Extract<keyof T, string>>(key: K): T[K];
42
+ subscribe: (subscriber: AppSubscriber<T>) => () => void;
43
+ registerMiddleware(...middlewares: Middleware<StateTypes<T>>[]): void;
44
+ private emit;
45
+ }
46
+ /**
47
+ * Create Galena
48
+ *
49
+ * Galena is designed to house one or more units of `State`
50
+ * and exist as a pseudo global application state.
51
+ *
52
+ * By design, each of its `State` units have isolated reactivity
53
+ * that prevents entire state trees from updating when a single
54
+ * unit changes.
55
+ *
56
+ * This is dissimilar to redux-like models where downstream reconciliations
57
+ * will propagate everwhere a given store is read from. In galena, downstream
58
+ * reconciliations occur only for consumers of the slice of state that
59
+ * changed - making it safer to use with more frequent state changes.
60
+ *
61
+ * ```typescript
62
+ * import { createGalena } from "@figliolia/galena";
63
+ *
64
+ * const AppState = createGalena({
65
+ * // your reactive instances
66
+ * }, ...middleware);
67
+ *
68
+ * // to retreive and work with an individual unit
69
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
70
+ *
71
+ * // to run a callback anytime a unit of state changes
72
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
73
+ * // do something with the `State` instance that updated
74
+ * });
75
+ * ```
76
+ */
77
+ declare const createGalena: <T extends Record<string, State<any>>>(...args: ConstructorParameters<typeof Galena<T>>) => Galena<T>;
78
+ //#endregion
79
+ export { Galena, createGalena };
80
+ //# sourceMappingURL=Galena.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Galena.d.mts","names":[],"sources":["../src/Galena.ts"],"mappings":";;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,MAAA,WAAiB,MAAA,SAAe,KAAA;EAAA,SAGzB,KAAA,EAAO,CAAA;EAAA,QAFjB,OAAA;cAEU,KAAA,EAAO,CAAA,KACpB,UAAA,EAAY,UAAA,CAAW,UAAA,CAAW,CAAA;EAKhC,GAAA,WAAc,OAAA,OAAc,CAAA,UAAA,CAAY,GAAA,EAAK,CAAA,GAAC,CAAA,CAAA,CAAA;EAI9C,SAAA,GAAa,UAAA,EAAY,aAAA,CAAc,CAAA;EAsBvC,kBAAA,CAAA,GAAsB,WAAA,EAAa,UAAA,CAAW,UAAA,CAAW,CAAA;EAAA,QAMxD,IAAA;AAAA;;;;;;;;;;;;;;;;;;AAsCV;;;;;;;;;;;;;;cAAa,YAAA,aAA0B,MAAA,SAAe,KAAA,WACjD,IAAA,EAAM,qBAAA,QAA6B,MAAA,CAAO,CAAA,OAAG,MAAA,CAAA,CAAA"}
@@ -0,0 +1,103 @@
1
+ import { EventEmitter } from "@figliolia/event-emitter";
2
+ //#region src/Galena.ts
3
+ /**
4
+ * Galena
5
+ *
6
+ * Galena is designed to house one or more units of `State`
7
+ * and exist as a pseudo global application state.
8
+ *
9
+ * By design, each of its `State` units have isolated reactivity
10
+ * that prevents entire state trees from updating when a single
11
+ * unit changes.
12
+ *
13
+ * This is dissimilar to redux-like models where downstream reconciliations
14
+ * will propagate everwhere a given store is read from. In galena, downstream
15
+ * reconciliations occur only for consumers of the slice of state that
16
+ * changed - making it safer to use with more frequent state changes.
17
+ *
18
+ * ```typescript
19
+ * import { Galena } from "@figliolia/galena";
20
+ *
21
+ * const AppState = new Galena({
22
+ * // your reactive instances
23
+ * }, ...middleware);
24
+ *
25
+ * // to retreive and work with an individual unit
26
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
27
+ *
28
+ * // to run a callback anytime a unit of state changes
29
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
30
+ * // do something with the `State` instance that updated
31
+ * });
32
+ * ```
33
+ */
34
+ var Galena = class {
35
+ Emitter = new EventEmitter();
36
+ constructor(state, ...middleware) {
37
+ this.state = state;
38
+ this.registerMiddleware(...middleware);
39
+ }
40
+ get(key) {
41
+ return this.state[key];
42
+ }
43
+ subscribe = (subscriber) => {
44
+ const ID = this.Emitter.on("change", subscriber);
45
+ const unsubscribers = [];
46
+ for (const key in this.state) {
47
+ const instance = this.state[key];
48
+ if (!instance) continue;
49
+ unsubscribers.push(instance.subscribe(() => this.emit({
50
+ state: this.state,
51
+ updated: instance
52
+ })));
53
+ }
54
+ return () => {
55
+ this.Emitter.off("change", ID);
56
+ while (unsubscribers.length) unsubscribers.pop?.()?.();
57
+ };
58
+ };
59
+ registerMiddleware(...middlewares) {
60
+ for (const key in this.state) this.state[key]?.registerMiddleware?.(...middlewares);
61
+ }
62
+ emit(event) {
63
+ this.Emitter.emit("change", event);
64
+ }
65
+ };
66
+ /**
67
+ * Create Galena
68
+ *
69
+ * Galena is designed to house one or more units of `State`
70
+ * and exist as a pseudo global application state.
71
+ *
72
+ * By design, each of its `State` units have isolated reactivity
73
+ * that prevents entire state trees from updating when a single
74
+ * unit changes.
75
+ *
76
+ * This is dissimilar to redux-like models where downstream reconciliations
77
+ * will propagate everwhere a given store is read from. In galena, downstream
78
+ * reconciliations occur only for consumers of the slice of state that
79
+ * changed - making it safer to use with more frequent state changes.
80
+ *
81
+ * ```typescript
82
+ * import { createGalena } from "@figliolia/galena";
83
+ *
84
+ * const AppState = createGalena({
85
+ * // your reactive instances
86
+ * }, ...middleware);
87
+ *
88
+ * // to retreive and work with an individual unit
89
+ * const myUnit = AppState.get("<key>"); // Returns State<T>
90
+ *
91
+ * // to run a callback anytime a unit of state changes
92
+ * const unsubscribe = AppState.subscribe(({ updated }) => {
93
+ * // do something with the `State` instance that updated
94
+ * });
95
+ * ```
96
+ */
97
+ const createGalena = (...args) => {
98
+ return new Galena(...args);
99
+ };
100
+ //#endregion
101
+ export { Galena, createGalena };
102
+
103
+ //# sourceMappingURL=Galena.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Galena.mjs","names":[],"sources":["../src/Galena.ts"],"sourcesContent":["import { EventEmitter } from \"@figliolia/event-emitter\";\nimport type { Middleware } from \"./Middleware\";\nimport type { State } from \"./State\";\nimport type { AppSubscriber, GalenaSnapshot, StateTypes } from \"./types\";\n\n/**\n * Galena\n *\n * Galena is designed to house one or more units of `State`\n * and exist as a pseudo global application state.\n *\n * By design, each of its `State` units have isolated reactivity\n * that prevents entire state trees from updating when a single\n * unit changes.\n *\n * This is dissimilar to redux-like models where downstream reconciliations\n * will propagate everwhere a given store is read from. In galena, downstream\n * reconciliations occur only for consumers of the slice of state that\n * changed - making it safer to use with more frequent state changes.\n *\n * ```typescript\n * import { Galena } from \"@figliolia/galena\";\n *\n * const AppState = new Galena({\n * // your reactive instances\n * }, ...middleware);\n *\n * // to retreive and work with an individual unit\n * const myUnit = AppState.get(\"<key>\"); // Returns State<T>\n *\n * // to run a callback anytime a unit of state changes\n * const unsubscribe = AppState.subscribe(({ updated }) => {\n * // do something with the `State` instance that updated\n * });\n * ```\n */\nexport class Galena<T extends Record<string, State<any>>> {\n private Emitter = new EventEmitter<{ change: GalenaSnapshot<T> }>();\n constructor(\n public readonly state: T,\n ...middleware: Middleware<StateTypes<T>>[]\n ) {\n this.registerMiddleware(...middleware);\n }\n\n public get<K extends Extract<keyof T, string>>(key: K) {\n return this.state[key];\n }\n\n public subscribe = (subscriber: AppSubscriber<T>) => {\n const ID = this.Emitter.on(\"change\", subscriber);\n const unsubscribers: (() => void)[] = [];\n for (const key in this.state) {\n const instance = this.state[key];\n if (!instance) {\n continue;\n }\n unsubscribers.push(\n instance.subscribe(() =>\n this.emit({ state: this.state, updated: instance }),\n ),\n );\n }\n return () => {\n this.Emitter.off(\"change\", ID);\n while (unsubscribers.length) {\n unsubscribers.pop?.()?.();\n }\n };\n };\n\n public registerMiddleware(...middlewares: Middleware<StateTypes<T>>[]) {\n for (const key in this.state) {\n this.state[key]?.registerMiddleware?.(...middlewares);\n }\n }\n\n private emit<K extends Extract<keyof T, string>>(\n event: GalenaSnapshot<T, K>,\n ) {\n this.Emitter.emit(\"change\", event);\n }\n}\n\n/**\n * Create Galena\n *\n * Galena is designed to house one or more units of `State`\n * and exist as a pseudo global application state.\n *\n * By design, each of its `State` units have isolated reactivity\n * that prevents entire state trees from updating when a single\n * unit changes.\n *\n * This is dissimilar to redux-like models where downstream reconciliations\n * will propagate everwhere a given store is read from. In galena, downstream\n * reconciliations occur only for consumers of the slice of state that\n * changed - making it safer to use with more frequent state changes.\n *\n * ```typescript\n * import { createGalena } from \"@figliolia/galena\";\n *\n * const AppState = createGalena({\n * // your reactive instances\n * }, ...middleware);\n *\n * // to retreive and work with an individual unit\n * const myUnit = AppState.get(\"<key>\"); // Returns State<T>\n *\n * // to run a callback anytime a unit of state changes\n * const unsubscribe = AppState.subscribe(({ updated }) => {\n * // do something with the `State` instance that updated\n * });\n * ```\n */\nexport const createGalena = <T extends Record<string, State<any>>>(\n ...args: ConstructorParameters<typeof Galena<T>>\n) => {\n return new Galena(...args);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,SAAb,MAA0D;CACxD,UAAkB,IAAI,cAA6C;CACnE,YACE,OACA,GAAG,YACH;AAFgB,OAAA,QAAA;AAGhB,OAAK,mBAAmB,GAAG,WAAW;;CAGxC,IAA+C,KAAQ;AACrD,SAAO,KAAK,MAAM;;CAGpB,aAAoB,eAAiC;EACnD,MAAM,KAAK,KAAK,QAAQ,GAAG,UAAU,WAAW;EAChD,MAAM,gBAAgC,EAAE;AACxC,OAAK,MAAM,OAAO,KAAK,OAAO;GAC5B,MAAM,WAAW,KAAK,MAAM;AAC5B,OAAI,CAAC,SACH;AAEF,iBAAc,KACZ,SAAS,gBACP,KAAK,KAAK;IAAE,OAAO,KAAK;IAAO,SAAS;IAAU,CAAC,CACpD,CACF;;AAEH,eAAa;AACX,QAAK,QAAQ,IAAI,UAAU,GAAG;AAC9B,UAAO,cAAc,OACnB,eAAc,OAAO,IAAI;;;CAK/B,mBAA0B,GAAG,aAA0C;AACrE,OAAK,MAAM,OAAO,KAAK,MACrB,MAAK,MAAM,MAAM,qBAAqB,GAAG,YAAY;;CAIzD,KACE,OACA;AACA,OAAK,QAAQ,KAAK,UAAU,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCtC,MAAa,gBACX,GAAG,SACA;AACH,QAAO,IAAI,OAAO,GAAG,KAAK"}
@@ -0,0 +1,50 @@
1
+ require("./Galena.cjs");
2
+ let react = require("react");
3
+ //#region src/GalenaProvider.tsx
4
+ /**
5
+ * Create Galena Provider
6
+ *
7
+ * For dependency injection with Galena, you can use this
8
+ * function to produce a Context provider and a corresponding
9
+ * `useGalena` hook
10
+ *
11
+ * ```typescript
12
+ * import { Galena, createGalenaProvider } from "@figliolia/galena";
13
+ *
14
+ * const galena = new Galena({
15
+ * // state tree
16
+ * }, ...middleware);
17
+ *
18
+ * const { GalenaProvider, useGalena } = createGalenaProvider(galena);
19
+ * ```
20
+ *
21
+ * By wrapping your application in the `GalenaProvider` returned, you
22
+ * can access your instance anywhere in your react code by calling
23
+ * `useGalena()`
24
+ */
25
+ function createGalenaProvider(galena) {
26
+ const GalenaContext = (0, react.createContext)(galena);
27
+ /**
28
+ * Galena Provider
29
+ *
30
+ * A context provider for your `Galena` instance to work with
31
+ * React dependency injection
32
+ */
33
+ function GalenaProvider({ children }) {
34
+ return <GalenaContext.Provider value={galena}>{children}</GalenaContext.Provider>;
35
+ }
36
+ /**
37
+ * Use Galena
38
+ *
39
+ * Returns the instance of Galena provided by the `GalenaProvider`
40
+ */
41
+ function useGalena() {
42
+ return (0, react.useContext)(GalenaContext);
43
+ }
44
+ return {
45
+ GalenaProvider,
46
+ useGalena
47
+ };
48
+ }
49
+ //#endregion
50
+ exports.createGalenaProvider = createGalenaProvider;
@@ -0,0 +1,35 @@
1
+ import { Galena } from "./Galena.cjs";
2
+ import * as react from "react";
3
+ import { PropsWithChildren } from "react";
4
+
5
+ //#region src/GalenaProvider.d.ts
6
+ /**
7
+ * Create Galena Provider
8
+ *
9
+ * For dependency injection with Galena, you can use this
10
+ * function to produce a Context provider and a corresponding
11
+ * `useGalena` hook
12
+ *
13
+ * ```typescript
14
+ * import { Galena, createGalenaProvider } from "@figliolia/galena";
15
+ *
16
+ * const galena = new Galena({
17
+ * // state tree
18
+ * }, ...middleware);
19
+ *
20
+ * const { GalenaProvider, useGalena } = createGalenaProvider(galena);
21
+ * ```
22
+ *
23
+ * By wrapping your application in the `GalenaProvider` returned, you
24
+ * can access your instance anywhere in your react code by calling
25
+ * `useGalena()`
26
+ */
27
+ declare function createGalenaProvider<T extends Galena<any>>(galena: T): {
28
+ GalenaProvider: ({
29
+ children
30
+ }: PropsWithChildren) => react.JSX.Element;
31
+ useGalena: () => T;
32
+ };
33
+ //#endregion
34
+ export { createGalenaProvider };
35
+ //# sourceMappingURL=GalenaProvider.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GalenaProvider.d.cts","names":[],"sources":["../src/GalenaProvider.tsx"],"mappings":";;;;;;;;AAwBA;;;;;;;;;;;;;;;;;;iBAAgB,oBAAA,WAA+B,MAAA,MAAA,CAAa,MAAA,EAAQ,CAAA;;;KAQ5B,iBAAA,KAAiB,KAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,35 @@
1
+ import { Galena } from "./Galena.mjs";
2
+ import * as react from "react";
3
+ import { PropsWithChildren } from "react";
4
+
5
+ //#region src/GalenaProvider.d.ts
6
+ /**
7
+ * Create Galena Provider
8
+ *
9
+ * For dependency injection with Galena, you can use this
10
+ * function to produce a Context provider and a corresponding
11
+ * `useGalena` hook
12
+ *
13
+ * ```typescript
14
+ * import { Galena, createGalenaProvider } from "@figliolia/galena";
15
+ *
16
+ * const galena = new Galena({
17
+ * // state tree
18
+ * }, ...middleware);
19
+ *
20
+ * const { GalenaProvider, useGalena } = createGalenaProvider(galena);
21
+ * ```
22
+ *
23
+ * By wrapping your application in the `GalenaProvider` returned, you
24
+ * can access your instance anywhere in your react code by calling
25
+ * `useGalena()`
26
+ */
27
+ declare function createGalenaProvider<T extends Galena<any>>(galena: T): {
28
+ GalenaProvider: ({
29
+ children
30
+ }: PropsWithChildren) => react.JSX.Element;
31
+ useGalena: () => T;
32
+ };
33
+ //#endregion
34
+ export { createGalenaProvider };
35
+ //# sourceMappingURL=GalenaProvider.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GalenaProvider.d.mts","names":[],"sources":["../src/GalenaProvider.tsx"],"mappings":";;;;;;;;AAwBA;;;;;;;;;;;;;;;;;;iBAAgB,oBAAA,WAA+B,MAAA,MAAA,CAAa,MAAA,EAAQ,CAAA;;;KAQ5B,iBAAA,KAAiB,KAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,52 @@
1
+ import "./Galena.mjs";
2
+ import { createContext, useContext } from "react";
3
+ //#region src/GalenaProvider.tsx
4
+ /**
5
+ * Create Galena Provider
6
+ *
7
+ * For dependency injection with Galena, you can use this
8
+ * function to produce a Context provider and a corresponding
9
+ * `useGalena` hook
10
+ *
11
+ * ```typescript
12
+ * import { Galena, createGalenaProvider } from "@figliolia/galena";
13
+ *
14
+ * const galena = new Galena({
15
+ * // state tree
16
+ * }, ...middleware);
17
+ *
18
+ * const { GalenaProvider, useGalena } = createGalenaProvider(galena);
19
+ * ```
20
+ *
21
+ * By wrapping your application in the `GalenaProvider` returned, you
22
+ * can access your instance anywhere in your react code by calling
23
+ * `useGalena()`
24
+ */
25
+ function createGalenaProvider(galena) {
26
+ const GalenaContext = createContext(galena);
27
+ /**
28
+ * Galena Provider
29
+ *
30
+ * A context provider for your `Galena` instance to work with
31
+ * React dependency injection
32
+ */
33
+ function GalenaProvider({ children }) {
34
+ return <GalenaContext.Provider value={galena}>{children}</GalenaContext.Provider>;
35
+ }
36
+ /**
37
+ * Use Galena
38
+ *
39
+ * Returns the instance of Galena provided by the `GalenaProvider`
40
+ */
41
+ function useGalena() {
42
+ return useContext(GalenaContext);
43
+ }
44
+ return {
45
+ GalenaProvider,
46
+ useGalena
47
+ };
48
+ }
49
+ //#endregion
50
+ export { createGalenaProvider };
51
+
52
+ //# sourceMappingURL=GalenaProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GalenaProvider.mjs","names":[],"sources":["../src/GalenaProvider.tsx"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from \"react\";\nimport { type Galena } from \"./Galena\";\n\n/**\n * Create Galena Provider\n *\n * For dependency injection with Galena, you can use this\n * function to produce a Context provider and a corresponding\n * `useGalena` hook\n *\n * ```typescript\n * import { Galena, createGalenaProvider } from \"@figliolia/galena\";\n *\n * const galena = new Galena({\n * // state tree\n * }, ...middleware);\n *\n * const { GalenaProvider, useGalena } = createGalenaProvider(galena);\n * ```\n *\n * By wrapping your application in the `GalenaProvider` returned, you\n * can access your instance anywhere in your react code by calling\n * `useGalena()`\n */\nexport function createGalenaProvider<T extends Galena<any>>(galena: T) {\n const GalenaContext = createContext<T>(galena);\n /**\n * Galena Provider\n *\n * A context provider for your `Galena` instance to work with\n * React dependency injection\n */\n function GalenaProvider({ children }: PropsWithChildren) {\n return (\n <GalenaContext.Provider value={galena}>{children}</GalenaContext.Provider>\n );\n }\n /**\n * Use Galena\n *\n * Returns the instance of Galena provided by the `GalenaProvider`\n */\n function useGalena() {\n return useContext(GalenaContext);\n }\n return { GalenaProvider, useGalena };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,qBAA4C,QAAW;CACrE,MAAM,gBAAgB,cAAiB,OAAO;;;;;;;CAO9C,SAAS,eAAe,EAAE,YAA+B;AACvD,SACE,CAAC,cAAc,SAAS,OAAO,SAAS,SAAS,EAAE,cAAc;;;;;;;CAQrE,SAAS,YAAY;AACnB,SAAO,WAAW,cAAc;;AAElC,QAAO;EAAE;EAAgB;EAAW"}
@@ -0,0 +1,46 @@
1
+ const require_Middleware = require("./Middleware.cjs");
2
+ //#region src/Logger.ts
3
+ /**
4
+ * Logger
5
+ *
6
+ * A middleware for Redux-style logging! Each state transition
7
+ * will log to the console the `State` instance that changed
8
+ * along with a before and after snapshot of the current state:
9
+ *
10
+ * ```typescript
11
+ * const AppState = new Galena({}, new Logger());
12
+ * // or
13
+ * AppState.registerMiddlerware(new Logger());
14
+ * // or
15
+ * const MyState = new State(4, new Logger());
16
+ * // or
17
+ * MyState.registerMiddleware(new Logger());
18
+ * ```
19
+ */
20
+ var Logger = class extends require_Middleware.Middleware {
21
+ previousState = null;
22
+ onBeforeUpdate(state) {
23
+ this.previousState = state.getSnapshot();
24
+ }
25
+ onUpdate(state) {
26
+ console.log("%cMutation:", "color: rgb(187, 186, 186); font-weight: bold", "@", this.time);
27
+ console.log(" %cPrevious State", "color: #26ad65; font-weight: bold", this.previousState);
28
+ console.log(" %cNext State ", "color: rgb(17, 118, 249); font-weight: bold", state.getSnapshot());
29
+ }
30
+ /**
31
+ * Time
32
+ *
33
+ * Returns the time in which a given state transition completed
34
+ */
35
+ get time() {
36
+ const date = /* @__PURE__ */ new Date();
37
+ const mHours = date.getHours();
38
+ const hours = mHours > 12 ? mHours - 12 : mHours;
39
+ const mins = date.getMinutes();
40
+ const minutes = mins.toString().length === 1 ? `0${mins}` : mins;
41
+ const secs = date.getSeconds();
42
+ return `${hours}:${minutes}:${secs.toString().length === 1 ? `0${secs}` : secs}:${date.getMilliseconds()}`;
43
+ }
44
+ };
45
+ //#endregion
46
+ exports.Logger = Logger;
@@ -0,0 +1,35 @@
1
+ import { Middleware } from "./Middleware.cjs";
2
+ import { State } from "./State.cjs";
3
+
4
+ //#region src/Logger.d.ts
5
+ /**
6
+ * Logger
7
+ *
8
+ * A middleware for Redux-style logging! Each state transition
9
+ * will log to the console the `State` instance that changed
10
+ * along with a before and after snapshot of the current state:
11
+ *
12
+ * ```typescript
13
+ * const AppState = new Galena({}, new Logger());
14
+ * // or
15
+ * AppState.registerMiddlerware(new Logger());
16
+ * // or
17
+ * const MyState = new State(4, new Logger());
18
+ * // or
19
+ * MyState.registerMiddleware(new Logger());
20
+ * ```
21
+ */
22
+ declare class Logger<T = any> extends Middleware {
23
+ private previousState;
24
+ onBeforeUpdate(state: State<T>): void;
25
+ onUpdate(state: State<T>): void;
26
+ /**
27
+ * Time
28
+ *
29
+ * Returns the time in which a given state transition completed
30
+ */
31
+ private get time();
32
+ }
33
+ //#endregion
34
+ export { Logger };
35
+ //# sourceMappingURL=Logger.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.cts","names":[],"sources":["../src/Logger.ts"],"mappings":";;;;;;AAoBA;;;;;;;;;;;;;;;cAAa,MAAA,kBAAwB,UAAA;EAAA,QAC3B,aAAA;EAEC,cAAA,CAAe,KAAA,EAAO,KAAA,CAAM,CAAA;EAI5B,QAAA,CAAS,KAAA,EAAO,KAAA,CAAM,CAAA;EAAA;;;;;EAAA,YAwBnB,IAAA,CAAA;AAAA"}