@figliolia/galena 3.0.0 → 3.0.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.
Files changed (58) hide show
  1. package/dist/Galena.d.cts +1 -1
  2. package/dist/Galena.d.mts +1 -1
  3. package/dist/Logger.d.cts +1 -1
  4. package/dist/Logger.d.mts +1 -1
  5. package/dist/Profiler.cjs +1 -1
  6. package/dist/Profiler.d.cts +1 -1
  7. package/dist/Profiler.d.mts +1 -1
  8. package/dist/Profiler.mjs +1 -1
  9. package/dist/Profiler.mjs.map +1 -1
  10. package/dist/State.d.cts +1 -1
  11. package/dist/State.d.mts +1 -1
  12. package/dist/index.cjs +0 -10
  13. package/dist/index.d.cts +3 -8
  14. package/dist/index.d.mts +3 -8
  15. package/dist/index.mjs +1 -6
  16. package/dist/types.d.cts +1 -8
  17. package/dist/types.d.cts.map +1 -1
  18. package/dist/types.d.mts +1 -8
  19. package/dist/types.d.mts.map +1 -1
  20. package/package.json +1 -1
  21. package/dist/GalenaProvider.cjs +0 -50
  22. package/dist/GalenaProvider.d.cts +0 -35
  23. package/dist/GalenaProvider.d.cts.map +0 -1
  24. package/dist/GalenaProvider.d.mts +0 -35
  25. package/dist/GalenaProvider.d.mts.map +0 -1
  26. package/dist/GalenaProvider.mjs +0 -52
  27. package/dist/GalenaProvider.mjs.map +0 -1
  28. package/dist/commonHooks.cjs +0 -17
  29. package/dist/commonHooks.mjs +0 -18
  30. package/dist/commonHooks.mjs.map +0 -1
  31. package/dist/connect-multi.cjs +0 -42
  32. package/dist/connect-multi.d.cts +0 -10
  33. package/dist/connect-multi.d.cts.map +0 -1
  34. package/dist/connect-multi.d.mts +0 -10
  35. package/dist/connect-multi.d.mts.map +0 -1
  36. package/dist/connect-multi.mjs +0 -44
  37. package/dist/connect-multi.mjs.map +0 -1
  38. package/dist/connect.cjs +0 -41
  39. package/dist/connect.d.cts +0 -9
  40. package/dist/connect.d.cts.map +0 -1
  41. package/dist/connect.d.mts +0 -9
  42. package/dist/connect.d.mts.map +0 -1
  43. package/dist/connect.mjs +0 -43
  44. package/dist/connect.mjs.map +0 -1
  45. package/dist/createUseState.cjs +0 -47
  46. package/dist/createUseState.d.cts +0 -46
  47. package/dist/createUseState.d.cts.map +0 -1
  48. package/dist/createUseState.d.mts +0 -46
  49. package/dist/createUseState.d.mts.map +0 -1
  50. package/dist/createUseState.mjs +0 -49
  51. package/dist/createUseState.mjs.map +0 -1
  52. package/dist/useState.cjs +0 -45
  53. package/dist/useState.d.cts +0 -43
  54. package/dist/useState.d.cts.map +0 -1
  55. package/dist/useState.d.mts +0 -43
  56. package/dist/useState.d.mts.map +0 -1
  57. package/dist/useState.mjs +0 -47
  58. package/dist/useState.mjs.map +0 -1
package/dist/Galena.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { Middleware } from "./Middleware.cjs";
2
1
  import { AppSubscriber, StateTypes } from "./types.cjs";
3
2
  import { State } from "./State.cjs";
3
+ import { Middleware } from "./Middleware.cjs";
4
4
 
5
5
  //#region src/Galena.d.ts
6
6
  /**
package/dist/Galena.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { Middleware } from "./Middleware.mjs";
2
1
  import { AppSubscriber, StateTypes } from "./types.mjs";
3
2
  import { State } from "./State.mjs";
3
+ import { Middleware } from "./Middleware.mjs";
4
4
 
5
5
  //#region src/Galena.d.ts
6
6
  /**
package/dist/Logger.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.cjs";
2
1
  import { State } from "./State.cjs";
2
+ import { Middleware } from "./Middleware.cjs";
3
3
 
4
4
  //#region src/Logger.d.ts
5
5
  /**
package/dist/Logger.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.mjs";
2
1
  import { State } from "./State.mjs";
2
+ import { Middleware } from "./Middleware.mjs";
3
3
 
4
4
  //#region src/Logger.d.ts
5
5
  /**
package/dist/Profiler.cjs CHANGED
@@ -31,7 +31,7 @@ var Profiler = class extends require_Middleware.Middleware {
31
31
  if (this.startTime === null) return;
32
32
  const diff = performance.now() - this.startTime;
33
33
  if (diff >= this.threshold) {
34
- console.warn(`A slow state transition of ${diff}ms was detected when transitioning the following piece of state`);
34
+ console.warn(`A slow state transition of ${diff.toFixed(1)}ms was detected when transitioning the following piece of state`);
35
35
  console.log(" %cPrevious State", "color: #26ad65; font-weight: bold", this.previousState);
36
36
  console.log(" %cCurrent State ", "color: rgb(17, 118, 249); font-weight: bold", state.getSnapshot());
37
37
  }
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.cjs";
2
1
  import { State } from "./State.cjs";
2
+ import { Middleware } from "./Middleware.cjs";
3
3
 
4
4
  //#region src/Profiler.d.ts
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.mjs";
2
1
  import { State } from "./State.mjs";
2
+ import { Middleware } from "./Middleware.mjs";
3
3
 
4
4
  //#region src/Profiler.d.ts
5
5
  /**
package/dist/Profiler.mjs CHANGED
@@ -31,7 +31,7 @@ var Profiler = class extends Middleware {
31
31
  if (this.startTime === null) return;
32
32
  const diff = performance.now() - this.startTime;
33
33
  if (diff >= this.threshold) {
34
- console.warn(`A slow state transition of ${diff}ms was detected when transitioning the following piece of state`);
34
+ console.warn(`A slow state transition of ${diff.toFixed(1)}ms was detected when transitioning the following piece of state`);
35
35
  console.log(" %cPrevious State", "color: #26ad65; font-weight: bold", this.previousState);
36
36
  console.log(" %cCurrent State ", "color: rgb(17, 118, 249); font-weight: bold", state.getSnapshot());
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Profiler.mjs","names":[],"sources":["../src/Profiler.ts"],"sourcesContent":["import { Middleware } from \"./Middleware\";\nimport type { State } from \"./State\";\n\n/**\n * Profiler\n *\n * A logger for state transitions exceeding a given\n * millisecond threshold\n *\n * ```typescript\n * const AppState = new Galena({}, new Profiler());\n * // or\n * AppState.registerMiddlerware(new Profiler());\n * // or\n * const MyState = new State(4, new Profiler());\n * // or\n * MyState.registerMiddleware(new Profiler());\n * ```\n */\nexport class Profiler<T = any> extends Middleware<T> {\n private previousState: T | null = null;\n private startTime: null | number = null;\n constructor(public readonly threshold = 16) {\n super();\n }\n\n public override onBeforeUpdate(state: State<T>) {\n this.startTime = performance.now();\n this.previousState = state.getSnapshot();\n }\n\n public override onUpdate(state: State<T>) {\n if (this.startTime === null) {\n return;\n }\n const diff = performance.now() - this.startTime;\n if (diff >= this.threshold) {\n console.warn(\n `A slow state transition of ${diff}ms was detected when transitioning the following piece of state`,\n );\n console.log(\n \" %cPrevious State\",\n \"color: #26ad65; font-weight: bold\",\n this.previousState,\n );\n console.log(\n \" %cCurrent State \",\n \"color: rgb(17, 118, 249); font-weight: bold\",\n state.getSnapshot(),\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,IAAa,WAAb,cAAuC,WAAc;CACnD,gBAAkC;CAClC,YAAmC;CACnC,YAAY,YAA4B,IAAI;AAC1C,SAAO;AADmB,OAAA,YAAA;;CAI5B,eAA+B,OAAiB;AAC9C,OAAK,YAAY,YAAY,KAAK;AAClC,OAAK,gBAAgB,MAAM,aAAa;;CAG1C,SAAyB,OAAiB;AACxC,MAAI,KAAK,cAAc,KACrB;EAEF,MAAM,OAAO,YAAY,KAAK,GAAG,KAAK;AACtC,MAAI,QAAQ,KAAK,WAAW;AAC1B,WAAQ,KACN,8BAA8B,KAAK,iEACpC;AACD,WAAQ,IACN,uBACA,qCACA,KAAK,cACN;AACD,WAAQ,IACN,0BACA,+CACA,MAAM,aAAa,CACpB"}
1
+ {"version":3,"file":"Profiler.mjs","names":[],"sources":["../src/Profiler.ts"],"sourcesContent":["import { Middleware } from \"./Middleware\";\nimport type { State } from \"./State\";\n\n/**\n * Profiler\n *\n * A logger for state transitions exceeding a given\n * millisecond threshold\n *\n * ```typescript\n * const AppState = new Galena({}, new Profiler());\n * // or\n * AppState.registerMiddlerware(new Profiler());\n * // or\n * const MyState = new State(4, new Profiler());\n * // or\n * MyState.registerMiddleware(new Profiler());\n * ```\n */\nexport class Profiler<T = any> extends Middleware<T> {\n private previousState: T | null = null;\n private startTime: null | number = null;\n constructor(public readonly threshold = 16) {\n super();\n }\n\n public override onBeforeUpdate(state: State<T>) {\n this.startTime = performance.now();\n this.previousState = state.getSnapshot();\n }\n\n public override onUpdate(state: State<T>) {\n if (this.startTime === null) {\n return;\n }\n const diff = performance.now() - this.startTime;\n if (diff >= this.threshold) {\n console.warn(\n `A slow state transition of ${diff.toFixed(1)}ms was detected when transitioning the following piece of state`,\n );\n console.log(\n \" %cPrevious State\",\n \"color: #26ad65; font-weight: bold\",\n this.previousState,\n );\n console.log(\n \" %cCurrent State \",\n \"color: rgb(17, 118, 249); font-weight: bold\",\n state.getSnapshot(),\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,IAAa,WAAb,cAAuC,WAAc;CACnD,gBAAkC;CAClC,YAAmC;CACnC,YAAY,YAA4B,IAAI;AAC1C,SAAO;AADmB,OAAA,YAAA;;CAI5B,eAA+B,OAAiB;AAC9C,OAAK,YAAY,YAAY,KAAK;AAClC,OAAK,gBAAgB,MAAM,aAAa;;CAG1C,SAAyB,OAAiB;AACxC,MAAI,KAAK,cAAc,KACrB;EAEF,MAAM,OAAO,YAAY,KAAK,GAAG,KAAK;AACtC,MAAI,QAAQ,KAAK,WAAW;AAC1B,WAAQ,KACN,8BAA8B,KAAK,QAAQ,EAAE,CAAC,iEAC/C;AACD,WAAQ,IACN,uBACA,qCACA,KAAK,cACN;AACD,WAAQ,IACN,0BACA,+CACA,MAAM,aAAa,CACpB"}
package/dist/State.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.cjs";
2
1
  import { NonFunction, Setter, Subscriber } from "./types.cjs";
2
+ import { Middleware } from "./Middleware.cjs";
3
3
 
4
4
  //#region src/State.d.ts
5
5
  /**
package/dist/State.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Middleware } from "./Middleware.mjs";
2
1
  import { NonFunction, Setter, Subscriber } from "./types.mjs";
2
+ import { Middleware } from "./Middleware.mjs";
3
3
 
4
4
  //#region src/State.d.ts
5
5
  /**
package/dist/index.cjs CHANGED
@@ -1,23 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_connect = require("./connect.cjs");
3
- const require_connect_multi = require("./connect-multi.cjs");
4
- const require_createUseState = require("./createUseState.cjs");
5
2
  const require_Galena = require("./Galena.cjs");
6
- const require_GalenaProvider = require("./GalenaProvider.cjs");
7
3
  const require_Middleware = require("./Middleware.cjs");
8
4
  const require_Logger = require("./Logger.cjs");
9
5
  const require_Profiler = require("./Profiler.cjs");
10
6
  const require_State = require("./State.cjs");
11
- const require_useState = require("./useState.cjs");
12
7
  exports.Galena = require_Galena.Galena;
13
8
  exports.Logger = require_Logger.Logger;
14
9
  exports.Middleware = require_Middleware.Middleware;
15
10
  exports.Profiler = require_Profiler.Profiler;
16
11
  exports.State = require_State.State;
17
- exports.connect = require_connect.connect;
18
- exports.connectMulti = require_connect_multi.connectMulti;
19
12
  exports.createGalena = require_Galena.createGalena;
20
- exports.createGalenaProvider = require_GalenaProvider.createGalenaProvider;
21
13
  exports.createState = require_State.createState;
22
- exports.createUseState = require_createUseState.createUseState;
23
- exports.useState = require_useState.useState;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,7 @@
1
- import { Middleware } from "./Middleware.cjs";
2
- import { AppSubscriber, DerivedArguments, DerivedSelector, GalenaSnapshot, NonFunction, PartialSupport, SetComplement, SetDifference, Setter, StateTypes, Subscriber, Subtract } from "./types.cjs";
1
+ import { AppSubscriber, GalenaSnapshot, NonFunction, PartialSupport, Setter, StateTypes, Subscriber } from "./types.cjs";
3
2
  import { State, createState } from "./State.cjs";
4
- import { connect } from "./connect.cjs";
5
- import { ReactiveStates, connectMulti } from "./connect-multi.cjs";
6
- import { createUseState } from "./createUseState.cjs";
3
+ import { Middleware } from "./Middleware.cjs";
7
4
  import { Galena, createGalena } from "./Galena.cjs";
8
- import { createGalenaProvider } from "./GalenaProvider.cjs";
9
5
  import { Logger } from "./Logger.cjs";
10
6
  import { Profiler } from "./Profiler.cjs";
11
- import { useState } from "./useState.cjs";
12
- export { AppSubscriber, DerivedArguments, DerivedSelector, Galena, GalenaSnapshot, Logger, Middleware, NonFunction, PartialSupport, Profiler, ReactiveStates, SetComplement, SetDifference, Setter, State, StateTypes, Subscriber, Subtract, connect, connectMulti, createGalena, createGalenaProvider, createState, createUseState, useState };
7
+ export { AppSubscriber, Galena, GalenaSnapshot, Logger, Middleware, NonFunction, PartialSupport, Profiler, Setter, State, StateTypes, Subscriber, createGalena, createState };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,7 @@
1
- import { Middleware } from "./Middleware.mjs";
2
- import { AppSubscriber, DerivedArguments, DerivedSelector, GalenaSnapshot, NonFunction, PartialSupport, SetComplement, SetDifference, Setter, StateTypes, Subscriber, Subtract } from "./types.mjs";
1
+ import { AppSubscriber, GalenaSnapshot, NonFunction, PartialSupport, Setter, StateTypes, Subscriber } from "./types.mjs";
3
2
  import { State, createState } from "./State.mjs";
4
- import { connect } from "./connect.mjs";
5
- import { ReactiveStates, connectMulti } from "./connect-multi.mjs";
6
- import { createUseState } from "./createUseState.mjs";
3
+ import { Middleware } from "./Middleware.mjs";
7
4
  import { Galena, createGalena } from "./Galena.mjs";
8
- import { createGalenaProvider } from "./GalenaProvider.mjs";
9
5
  import { Logger } from "./Logger.mjs";
10
6
  import { Profiler } from "./Profiler.mjs";
11
- import { useState } from "./useState.mjs";
12
- export { AppSubscriber, DerivedArguments, DerivedSelector, Galena, GalenaSnapshot, Logger, Middleware, NonFunction, PartialSupport, Profiler, ReactiveStates, SetComplement, SetDifference, Setter, State, StateTypes, Subscriber, Subtract, connect, connectMulti, createGalena, createGalenaProvider, createState, createUseState, useState };
7
+ export { AppSubscriber, Galena, GalenaSnapshot, Logger, Middleware, NonFunction, PartialSupport, Profiler, Setter, State, StateTypes, Subscriber, createGalena, createState };
package/dist/index.mjs CHANGED
@@ -1,11 +1,6 @@
1
- import { connect } from "./connect.mjs";
2
- import { connectMulti } from "./connect-multi.mjs";
3
- import { createUseState } from "./createUseState.mjs";
4
1
  import { Galena, createGalena } from "./Galena.mjs";
5
- import { createGalenaProvider } from "./GalenaProvider.mjs";
6
2
  import { Middleware } from "./Middleware.mjs";
7
3
  import { Logger } from "./Logger.mjs";
8
4
  import { Profiler } from "./Profiler.mjs";
9
5
  import { State, createState } from "./State.mjs";
10
- import { useState } from "./useState.mjs";
11
- export { Galena, Logger, Middleware, Profiler, State, connect, connectMulti, createGalena, createGalenaProvider, createState, createUseState, useState };
6
+ export { Galena, Logger, Middleware, Profiler, State, createGalena, createState };
package/dist/types.d.cts CHANGED
@@ -11,13 +11,6 @@ interface GalenaSnapshot<T extends Record<string, State<any>>, K extends Extract
11
11
  }
12
12
  type AppSubscriber<T extends Record<string, State<any>>, K extends Extract<keyof T, string> = Extract<keyof T, string>> = ((payload: GalenaSnapshot<T, K>) => void) | (() => void);
13
13
  type StateTypes<T extends Record<string, State<any>>> = ReturnType<T[keyof T]["getSnapshot"]>;
14
- type SetDifference<A, B> = A extends B ? never : A;
15
- type SetComplement<A, A1 extends A> = SetDifference<A, A1>;
16
- type Subtract<T extends T1, T1 extends object> = Pick<T, SetComplement<keyof T, keyof T1>>;
17
- type DerivedArguments<StateInstances extends State<any>[]> = { [I in keyof StateInstances]: ReturnType<StateInstances[I]["getSnapshot"]> } & {
18
- length: number;
19
- };
20
- type DerivedSelector<StateInstances extends State<any>[]> = (state: DerivedArguments<StateInstances>, ownProps: any) => Record<string, any>;
21
14
  //#endregion
22
- export { AppSubscriber, DerivedArguments, DerivedSelector, GalenaSnapshot, NonFunction, PartialSupport, SetComplement, SetDifference, Setter, StateTypes, Subscriber, Subtract };
15
+ export { AppSubscriber, GalenaSnapshot, NonFunction, PartialSupport, Setter, StateTypes, Subscriber };
23
16
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,WAAA,MAAiB,CAAA,cAAc,IAAA,2BAA8B,CAAA;AAAA,KAE7D,cAAA,MAAoB,CAAA,SAAU,MAAA,gBAAsB,OAAA,CAAQ,CAAA,IAAK,CAAA;AAAA,KAEjE,MAAA,MACR,WAAA,CAAY,CAAA,MACV,SAAA,EAAW,WAAA,CAAY,CAAA,MAAO,WAAA,CAAY,CAAA,IAAK,OAAA,CAAQ,WAAA,CAAY,CAAA;AAAA,KAE7D,UAAA,QAAkB,KAAA,EAAO,WAAA,CAAY,CAAA;AAAA,UAEhC,cAAA,WACL,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA;EAEnD,OAAA,EAAS,CAAA,CAAE,CAAA;EACX,KAAA,EAAO,CAAA;AAAA;AAAA,KAGG,aAAA,WACA,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA,eAC/C,OAAA,EAAS,cAAA,CAAe,CAAA,EAAG,CAAA;AAAA,KAErB,UAAA,WAAqB,MAAA,SAAe,KAAA,UAAe,UAAA,CAC7D,CAAA,OAAQ,CAAA;AAAA,KAGE,aAAA,SAAsB,CAAA,SAAU,CAAA,WAAY,CAAA;AAAA,KAE5C,aAAA,eAA4B,CAAA,IAAK,aAAA,CAAc,CAAA,EAAG,EAAA;AAAA,KAElD,QAAA,WAAmB,EAAA,uBAAyB,IAAA,CACtD,CAAA,EACA,aAAA,OAAoB,CAAA,QAAS,EAAA;AAAA,KAGnB,gBAAA,wBAAwC,KAAA,yBACtC,cAAA,GAAiB,UAAA,CAAW,cAAA,CAAe,CAAA;EACnD,MAAA;AAAA;AAAA,KAEM,eAAA,wBAAuC,KAAA,YACjD,KAAA,EAAO,gBAAA,CAAiB,cAAA,GACxB,QAAA,UACG,MAAA"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,WAAA,MAAiB,CAAA,cAAc,IAAA,2BAA8B,CAAA;AAAA,KAE7D,cAAA,MAAoB,CAAA,SAAU,MAAA,gBAAsB,OAAA,CAAQ,CAAA,IAAK,CAAA;AAAA,KAEjE,MAAA,MACR,WAAA,CAAY,CAAA,MACV,SAAA,EAAW,WAAA,CAAY,CAAA,MAAO,WAAA,CAAY,CAAA,IAAK,OAAA,CAAQ,WAAA,CAAY,CAAA;AAAA,KAE7D,UAAA,QAAkB,KAAA,EAAO,WAAA,CAAY,CAAA;AAAA,UAEhC,cAAA,WACL,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA;EAEnD,OAAA,EAAS,CAAA,CAAE,CAAA;EACX,KAAA,EAAO,CAAA;AAAA;AAAA,KAGG,aAAA,WACA,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA,eAC/C,OAAA,EAAS,cAAA,CAAe,CAAA,EAAG,CAAA;AAAA,KAErB,UAAA,WAAqB,MAAA,SAAe,KAAA,UAAe,UAAA,CAC7D,CAAA,OAAQ,CAAA"}
package/dist/types.d.mts CHANGED
@@ -11,13 +11,6 @@ interface GalenaSnapshot<T extends Record<string, State<any>>, K extends Extract
11
11
  }
12
12
  type AppSubscriber<T extends Record<string, State<any>>, K extends Extract<keyof T, string> = Extract<keyof T, string>> = ((payload: GalenaSnapshot<T, K>) => void) | (() => void);
13
13
  type StateTypes<T extends Record<string, State<any>>> = ReturnType<T[keyof T]["getSnapshot"]>;
14
- type SetDifference<A, B> = A extends B ? never : A;
15
- type SetComplement<A, A1 extends A> = SetDifference<A, A1>;
16
- type Subtract<T extends T1, T1 extends object> = Pick<T, SetComplement<keyof T, keyof T1>>;
17
- type DerivedArguments<StateInstances extends State<any>[]> = { [I in keyof StateInstances]: ReturnType<StateInstances[I]["getSnapshot"]> } & {
18
- length: number;
19
- };
20
- type DerivedSelector<StateInstances extends State<any>[]> = (state: DerivedArguments<StateInstances>, ownProps: any) => Record<string, any>;
21
14
  //#endregion
22
- export { AppSubscriber, DerivedArguments, DerivedSelector, GalenaSnapshot, NonFunction, PartialSupport, SetComplement, SetDifference, Setter, StateTypes, Subscriber, Subtract };
15
+ export { AppSubscriber, GalenaSnapshot, NonFunction, PartialSupport, Setter, StateTypes, Subscriber };
23
16
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,WAAA,MAAiB,CAAA,cAAc,IAAA,2BAA8B,CAAA;AAAA,KAE7D,cAAA,MAAoB,CAAA,SAAU,MAAA,gBAAsB,OAAA,CAAQ,CAAA,IAAK,CAAA;AAAA,KAEjE,MAAA,MACR,WAAA,CAAY,CAAA,MACV,SAAA,EAAW,WAAA,CAAY,CAAA,MAAO,WAAA,CAAY,CAAA,IAAK,OAAA,CAAQ,WAAA,CAAY,CAAA;AAAA,KAE7D,UAAA,QAAkB,KAAA,EAAO,WAAA,CAAY,CAAA;AAAA,UAEhC,cAAA,WACL,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA;EAEnD,OAAA,EAAS,CAAA,CAAE,CAAA;EACX,KAAA,EAAO,CAAA;AAAA;AAAA,KAGG,aAAA,WACA,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA,eAC/C,OAAA,EAAS,cAAA,CAAe,CAAA,EAAG,CAAA;AAAA,KAErB,UAAA,WAAqB,MAAA,SAAe,KAAA,UAAe,UAAA,CAC7D,CAAA,OAAQ,CAAA;AAAA,KAGE,aAAA,SAAsB,CAAA,SAAU,CAAA,WAAY,CAAA;AAAA,KAE5C,aAAA,eAA4B,CAAA,IAAK,aAAA,CAAc,CAAA,EAAG,EAAA;AAAA,KAElD,QAAA,WAAmB,EAAA,uBAAyB,IAAA,CACtD,CAAA,EACA,aAAA,OAAoB,CAAA,QAAS,EAAA;AAAA,KAGnB,gBAAA,wBAAwC,KAAA,yBACtC,cAAA,GAAiB,UAAA,CAAW,cAAA,CAAe,CAAA;EACnD,MAAA;AAAA;AAAA,KAEM,eAAA,wBAAuC,KAAA,YACjD,KAAA,EAAO,gBAAA,CAAiB,cAAA,GACxB,QAAA,UACG,MAAA"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,WAAA,MAAiB,CAAA,cAAc,IAAA,2BAA8B,CAAA;AAAA,KAE7D,cAAA,MAAoB,CAAA,SAAU,MAAA,gBAAsB,OAAA,CAAQ,CAAA,IAAK,CAAA;AAAA,KAEjE,MAAA,MACR,WAAA,CAAY,CAAA,MACV,SAAA,EAAW,WAAA,CAAY,CAAA,MAAO,WAAA,CAAY,CAAA,IAAK,OAAA,CAAQ,WAAA,CAAY,CAAA;AAAA,KAE7D,UAAA,QAAkB,KAAA,EAAO,WAAA,CAAY,CAAA;AAAA,UAEhC,cAAA,WACL,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA;EAEnD,OAAA,EAAS,CAAA,CAAE,CAAA;EACX,KAAA,EAAO,CAAA;AAAA;AAAA,KAGG,aAAA,WACA,MAAA,SAAe,KAAA,kBACf,OAAA,OAAc,CAAA,YAAa,OAAA,OAAc,CAAA,eAC/C,OAAA,EAAS,cAAA,CAAe,CAAA,EAAG,CAAA;AAAA,KAErB,UAAA,WAAqB,MAAA,SAAe,KAAA,UAAe,UAAA,CAC7D,CAAA,OAAQ,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figliolia/galena",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A performant state management library supporting middleware and a rich developer API",
5
5
  "homepage": "https://github.com/alexfigliolia/galena#readme",
6
6
  "license": "MIT",
@@ -1,50 +0,0 @@
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;
@@ -1,35 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,35 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,52 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,17 +0,0 @@
1
- let react = require("react");
2
- //#region src/commonHooks.ts
3
- function useStableSelector(selector) {
4
- const stableSelector = (0, react.useRef)(selector);
5
- (0, react.useEffect)(() => {
6
- stableSelector.current = ((...args) => selector(...args));
7
- }, [selector]);
8
- return stableSelector;
9
- }
10
- function useStateHookAPI(value, selector) {
11
- const state = (0, react.useSyncExternalStore)(value.subscribe, value.getSnapshot);
12
- const selectedValue = (0, react.useMemo)(() => selector.current(state), [state, selector]);
13
- return (0, react.useMemo)(() => [selectedValue, value.update], [selectedValue, value]);
14
- }
15
- //#endregion
16
- exports.useStableSelector = useStableSelector;
17
- exports.useStateHookAPI = useStateHookAPI;
@@ -1,18 +0,0 @@
1
- import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
2
- //#region src/commonHooks.ts
3
- function useStableSelector(selector) {
4
- const stableSelector = useRef(selector);
5
- useEffect(() => {
6
- stableSelector.current = ((...args) => selector(...args));
7
- }, [selector]);
8
- return stableSelector;
9
- }
10
- function useStateHookAPI(value, selector) {
11
- const state = useSyncExternalStore(value.subscribe, value.getSnapshot);
12
- const selectedValue = useMemo(() => selector.current(state), [state, selector]);
13
- return useMemo(() => [selectedValue, value.update], [selectedValue, value]);
14
- }
15
- //#endregion
16
- export { useStableSelector, useStateHookAPI };
17
-
18
- //# sourceMappingURL=commonHooks.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commonHooks.mjs","names":[],"sources":["../src/commonHooks.ts"],"sourcesContent":["import {\n type RefObject,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport type { State } from \"./State\";\nimport type { NonFunction } from \"./types\";\n\nexport function useStableSelector<F extends (...args: any[]) => any>(\n selector: F,\n) {\n const stableSelector = useRef(selector);\n\n useEffect(() => {\n stableSelector.current = ((...args: Parameters<typeof selector>) =>\n selector(...args)) as F;\n }, [selector]);\n\n return stableSelector;\n}\n\nexport function useStateHookAPI<T, U>(\n value: State<T>,\n selector: RefObject<(state: NonFunction<T>) => U>,\n) {\n const state = useSyncExternalStore(value.subscribe, value.getSnapshot);\n const selectedValue = useMemo(\n () => selector.current(state),\n [state, selector],\n );\n return useMemo(\n () => [selectedValue, value.update] as const,\n [selectedValue, value],\n );\n}\n"],"mappings":";;AAUA,SAAgB,kBACd,UACA;CACA,MAAM,iBAAiB,OAAO,SAAS;AAEvC,iBAAgB;AACd,iBAAe,YAAY,GAAG,SAC5B,SAAS,GAAG,KAAK;IAClB,CAAC,SAAS,CAAC;AAEd,QAAO;;AAGT,SAAgB,gBACd,OACA,UACA;CACA,MAAM,QAAQ,qBAAqB,MAAM,WAAW,MAAM,YAAY;CACtE,MAAM,gBAAgB,cACd,SAAS,QAAQ,MAAM,EAC7B,CAAC,OAAO,SAAS,CAClB;AACD,QAAO,cACC,CAAC,eAAe,MAAM,OAAO,EACnC,CAAC,eAAe,MAAM,CACvB"}
@@ -1,42 +0,0 @@
1
- let react = require("react");
2
- //#region src/connect-multi.tsx
3
- const connectMulti = (...states) => {
4
- return (selector) => {
5
- return (WrappedComponent) => {
6
- return class GalenaMultiComponent extends react.Component {
7
- state;
8
- listeners = [];
9
- constructor(props) {
10
- super(props);
11
- this.state = this.computeSelector();
12
- }
13
- static displayName = `GalenaMultiComponent(${WrappedComponent.displayName ?? WrappedComponent.name ?? "Component"})`;
14
- componentDidMount() {
15
- this.listeners = this.bindListeners();
16
- }
17
- UNSAFE_componentWillReceiveProps(nextProps) {
18
- if (nextProps !== this.props) this.setState(this.computeSelector(nextProps));
19
- }
20
- shouldComponentUpdate(nextProps, nextState) {
21
- return nextState !== this.state || nextProps !== this.props;
22
- }
23
- componentWillUnmount() {
24
- while (this.listeners.length) this.listeners.pop()?.();
25
- }
26
- bindListeners() {
27
- return states.map((state) => {
28
- return state.subscribe(() => this.setState(this.computeSelector()));
29
- });
30
- }
31
- computeSelector(props = this.props) {
32
- return selector(states.map((s) => s.getSnapshot()), props);
33
- }
34
- render() {
35
- return <WrappedComponent {...this.props} {...this.state} />;
36
- }
37
- };
38
- };
39
- };
40
- };
41
- //#endregion
42
- exports.connectMulti = connectMulti;
@@ -1,10 +0,0 @@
1
- import { DerivedSelector, Subtract } from "./types.cjs";
2
- import { State } from "./State.cjs";
3
- import { ComponentType } from "react";
4
-
5
- //#region src/connect-multi.d.ts
6
- declare const connectMulti: <StateInstances extends State<any>[]>(...states: StateInstances) => <Selector extends DerivedSelector<StateInstances>>(selector: Selector) => <ComponentProps extends ReturnType<Selector>>(WrappedComponent: ComponentType<ComponentProps>) => ComponentType<Subtract<ComponentProps, ReturnType<Selector>>>;
7
- type ReactiveStates<T extends ReturnType<typeof connectMulti>> = Parameters<Parameters<T>[0]>[0];
8
- //#endregion
9
- export { ReactiveStates, connectMulti };
10
- //# sourceMappingURL=connect-multi.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect-multi.d.cts","names":[],"sources":["../src/connect-multi.tsx"],"mappings":";;;;;cAIa,YAAA,0BAAuC,KAAA,YAC/C,MAAA,EAAQ,cAAA,uBAEc,eAAA,CAAgB,cAAA,GACvC,QAAA,EAAU,QAAA,6BAEqB,UAAA,CAAW,QAAA,GACxC,gBAAA,EAAkB,aAAA,CAAc,cAAA,MAC/B,aAAA,CAAc,QAAA,CAAS,cAAA,EAAgB,UAAA,CAAW,QAAA;AAAA,KA+D7C,cAAA,WAAyB,UAAA,QAAkB,YAAA,KACrD,UAAA,CAAW,UAAA,CAAW,CAAA"}
@@ -1,10 +0,0 @@
1
- import { DerivedSelector, Subtract } from "./types.mjs";
2
- import { State } from "./State.mjs";
3
- import { ComponentType } from "react";
4
-
5
- //#region src/connect-multi.d.ts
6
- declare const connectMulti: <StateInstances extends State<any>[]>(...states: StateInstances) => <Selector extends DerivedSelector<StateInstances>>(selector: Selector) => <ComponentProps extends ReturnType<Selector>>(WrappedComponent: ComponentType<ComponentProps>) => ComponentType<Subtract<ComponentProps, ReturnType<Selector>>>;
7
- type ReactiveStates<T extends ReturnType<typeof connectMulti>> = Parameters<Parameters<T>[0]>[0];
8
- //#endregion
9
- export { ReactiveStates, connectMulti };
10
- //# sourceMappingURL=connect-multi.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect-multi.d.mts","names":[],"sources":["../src/connect-multi.tsx"],"mappings":";;;;;cAIa,YAAA,0BAAuC,KAAA,YAC/C,MAAA,EAAQ,cAAA,uBAEc,eAAA,CAAgB,cAAA,GACvC,QAAA,EAAU,QAAA,6BAEqB,UAAA,CAAW,QAAA,GACxC,gBAAA,EAAkB,aAAA,CAAc,cAAA,MAC/B,aAAA,CAAc,QAAA,CAAS,cAAA,EAAgB,UAAA,CAAW,QAAA;AAAA,KA+D7C,cAAA,WAAyB,UAAA,QAAkB,YAAA,KACrD,UAAA,CAAW,UAAA,CAAW,CAAA"}
@@ -1,44 +0,0 @@
1
- import { Component } from "react";
2
- //#region src/connect-multi.tsx
3
- const connectMulti = (...states) => {
4
- return (selector) => {
5
- return (WrappedComponent) => {
6
- return class GalenaMultiComponent extends Component {
7
- state;
8
- listeners = [];
9
- constructor(props) {
10
- super(props);
11
- this.state = this.computeSelector();
12
- }
13
- static displayName = `GalenaMultiComponent(${WrappedComponent.displayName ?? WrappedComponent.name ?? "Component"})`;
14
- componentDidMount() {
15
- this.listeners = this.bindListeners();
16
- }
17
- UNSAFE_componentWillReceiveProps(nextProps) {
18
- if (nextProps !== this.props) this.setState(this.computeSelector(nextProps));
19
- }
20
- shouldComponentUpdate(nextProps, nextState) {
21
- return nextState !== this.state || nextProps !== this.props;
22
- }
23
- componentWillUnmount() {
24
- while (this.listeners.length) this.listeners.pop()?.();
25
- }
26
- bindListeners() {
27
- return states.map((state) => {
28
- return state.subscribe(() => this.setState(this.computeSelector()));
29
- });
30
- }
31
- computeSelector(props = this.props) {
32
- return selector(states.map((s) => s.getSnapshot()), props);
33
- }
34
- render() {
35
- return <WrappedComponent {...this.props} {...this.state} />;
36
- }
37
- };
38
- };
39
- };
40
- };
41
- //#endregion
42
- export { connectMulti };
43
-
44
- //# sourceMappingURL=connect-multi.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect-multi.mjs","names":[],"sources":["../src/connect-multi.tsx"],"sourcesContent":["import { Component, type ComponentType } from \"react\";\nimport type { State } from \"./State\";\nimport type { DerivedArguments, DerivedSelector, Subtract } from \"./types\";\n\nexport const connectMulti = <StateInstances extends State<any>[]>(\n ...states: StateInstances\n) => {\n return <Selector extends DerivedSelector<StateInstances>>(\n selector: Selector,\n ) => {\n return <ComponentProps extends ReturnType<Selector>>(\n WrappedComponent: ComponentType<ComponentProps>,\n ): ComponentType<Subtract<ComponentProps, ReturnType<Selector>>> => {\n type OwnProps = Subtract<ComponentProps, ReturnType<Selector>>;\n return class GalenaMultiComponent extends Component<\n OwnProps,\n ReturnType<Selector>\n > {\n override state: any;\n listeners: (() => void)[] = [];\n constructor(props: OwnProps) {\n super(props);\n this.state = this.computeSelector();\n }\n\n static displayName = `GalenaMultiComponent(${\n WrappedComponent.displayName ?? WrappedComponent.name ?? \"Component\"\n })`;\n\n public override componentDidMount() {\n this.listeners = this.bindListeners();\n }\n\n public override UNSAFE_componentWillReceiveProps(nextProps: OwnProps) {\n if (nextProps !== this.props) {\n this.setState(this.computeSelector(nextProps));\n }\n }\n\n public override shouldComponentUpdate(\n nextProps: OwnProps,\n nextState: ReturnType<Selector>,\n ) {\n return nextState !== this.state || nextProps !== this.props;\n }\n\n public override componentWillUnmount() {\n while (this.listeners.length) {\n this.listeners.pop()?.();\n }\n }\n\n private bindListeners() {\n return states.map(state => {\n return state.subscribe(() => this.setState(this.computeSelector()));\n });\n }\n\n private computeSelector(props: OwnProps = this.props) {\n return selector(\n states.map(s =>\n s.getSnapshot(),\n ) as DerivedArguments<StateInstances>,\n props,\n );\n }\n\n public override render() {\n return <WrappedComponent {...this.props} {...this.state} />;\n }\n };\n };\n };\n};\n\nexport type ReactiveStates<T extends ReturnType<typeof connectMulti>> =\n Parameters<Parameters<T>[0]>[0];\n"],"mappings":";;AAIA,MAAa,gBACX,GAAG,WACA;AACH,SACE,aACG;AACH,UACE,qBACkE;AAElE,UAAO,MAAM,6BAA6B,UAGxC;IACA;IACA,YAA4B,EAAE;IAC9B,YAAY,OAAiB;AAC3B,WAAM,MAAM;AACZ,UAAK,QAAQ,KAAK,iBAAiB;;IAGrC,OAAO,cAAc,wBACnB,iBAAiB,eAAe,iBAAiB,QAAQ,YAC1D;IAED,oBAAoC;AAClC,UAAK,YAAY,KAAK,eAAe;;IAGvC,iCAAiD,WAAqB;AACpE,SAAI,cAAc,KAAK,MACrB,MAAK,SAAS,KAAK,gBAAgB,UAAU,CAAC;;IAIlD,sBACE,WACA,WACA;AACA,YAAO,cAAc,KAAK,SAAS,cAAc,KAAK;;IAGxD,uBAAuC;AACrC,YAAO,KAAK,UAAU,OACpB,MAAK,UAAU,KAAK,IAAI;;IAI5B,gBAAwB;AACtB,YAAO,OAAO,KAAI,UAAS;AACzB,aAAO,MAAM,gBAAgB,KAAK,SAAS,KAAK,iBAAiB,CAAC,CAAC;OACnE;;IAGJ,gBAAwB,QAAkB,KAAK,OAAO;AACpD,YAAO,SACL,OAAO,KAAI,MACT,EAAE,aAAa,CAChB,EACD,MACD;;IAGH,SAAyB;AACvB,YAAO,CAAC,qBAAqB,KAAK,WAAW,KAAK"}
package/dist/connect.cjs DELETED
@@ -1,41 +0,0 @@
1
- let react = require("react");
2
- //#region src/connect.tsx
3
- const connect = (state) => {
4
- return (selection) => {
5
- return (WrappedComponent) => {
6
- return class GalenaComponent extends react.Component {
7
- state;
8
- listener = null;
9
- constructor(props) {
10
- super(props);
11
- this.update = this.update.bind(this);
12
- this.state = selection(state.getSnapshot(), this.props);
13
- }
14
- static displayName = `GalenaComponent(${(WrappedComponent.displayName ?? WrappedComponent.name) || "Component"})`;
15
- componentDidMount() {
16
- this.listener = state.subscribe((state) => this.update(state));
17
- }
18
- UNSAFE_componentWillReceiveProps(nextProps) {
19
- if (nextProps !== this.props) this.update(state.getSnapshot(), nextProps);
20
- }
21
- shouldComponentUpdate(nextProps, nextState) {
22
- return nextState !== this.state || nextProps !== this.props;
23
- }
24
- componentWillUnmount() {
25
- if (this.listener) {
26
- this.listener();
27
- this.listener = null;
28
- }
29
- }
30
- update(nextState, ownProps = this.props) {
31
- this.setState(selection(nextState, ownProps));
32
- }
33
- render() {
34
- return <WrappedComponent {...this.props} {...this.state} />;
35
- }
36
- };
37
- };
38
- };
39
- };
40
- //#endregion
41
- exports.connect = connect;
@@ -1,9 +0,0 @@
1
- import { Subtract } from "./types.cjs";
2
- import { State } from "./State.cjs";
3
- import { ComponentType } from "react";
4
-
5
- //#region src/connect.d.ts
6
- declare const connect: <StateInstance extends State<any>>(state: StateInstance) => <SelectorFunction extends (state: ReturnType<StateInstance["getSnapshot"]>, ownProps: any) => Record<string, any>>(selection: SelectorFunction) => <ComponentProps extends ReturnType<SelectorFunction>>(WrappedComponent: ComponentType<ComponentProps>) => ComponentType<Subtract<ComponentProps, ReturnType<SelectorFunction>>>;
7
- //#endregion
8
- export { connect };
9
- //# sourceMappingURL=connect.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.d.cts","names":[],"sources":["../src/connect.tsx"],"mappings":";;;;;cAIa,OAAA,yBAAiC,KAAA,OAC5C,KAAA,EAAO,aAAA,gCAKH,KAAA,EAAK,UAAA,CAAA,aAAA,kBACL,QAAA,UACG,MAAA,eAEL,SAAA,EAAW,gBAAA,6BAGW,UAAA,CAAA,gBAAA,GACpB,gBAAA,EAAkB,aAAA,CAAc,cAAA,MAC/B,aAAA,CAAc,QAAA,CAAS,cAAA,EAAc,UAAA,CAAA,gBAAA"}
@@ -1,9 +0,0 @@
1
- import { Subtract } from "./types.mjs";
2
- import { State } from "./State.mjs";
3
- import { ComponentType } from "react";
4
-
5
- //#region src/connect.d.ts
6
- declare const connect: <StateInstance extends State<any>>(state: StateInstance) => <SelectorFunction extends (state: ReturnType<StateInstance["getSnapshot"]>, ownProps: any) => Record<string, any>>(selection: SelectorFunction) => <ComponentProps extends ReturnType<SelectorFunction>>(WrappedComponent: ComponentType<ComponentProps>) => ComponentType<Subtract<ComponentProps, ReturnType<SelectorFunction>>>;
7
- //#endregion
8
- export { connect };
9
- //# sourceMappingURL=connect.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.d.mts","names":[],"sources":["../src/connect.tsx"],"mappings":";;;;;cAIa,OAAA,yBAAiC,KAAA,OAC5C,KAAA,EAAO,aAAA,gCAKH,KAAA,EAAK,UAAA,CAAA,aAAA,kBACL,QAAA,UACG,MAAA,eAEL,SAAA,EAAW,gBAAA,6BAGW,UAAA,CAAA,gBAAA,GACpB,gBAAA,EAAkB,aAAA,CAAc,cAAA,MAC/B,aAAA,CAAc,QAAA,CAAS,cAAA,EAAc,UAAA,CAAA,gBAAA"}
package/dist/connect.mjs DELETED
@@ -1,43 +0,0 @@
1
- import { Component } from "react";
2
- //#region src/connect.tsx
3
- const connect = (state) => {
4
- return (selection) => {
5
- return (WrappedComponent) => {
6
- return class GalenaComponent extends Component {
7
- state;
8
- listener = null;
9
- constructor(props) {
10
- super(props);
11
- this.update = this.update.bind(this);
12
- this.state = selection(state.getSnapshot(), this.props);
13
- }
14
- static displayName = `GalenaComponent(${(WrappedComponent.displayName ?? WrappedComponent.name) || "Component"})`;
15
- componentDidMount() {
16
- this.listener = state.subscribe((state) => this.update(state));
17
- }
18
- UNSAFE_componentWillReceiveProps(nextProps) {
19
- if (nextProps !== this.props) this.update(state.getSnapshot(), nextProps);
20
- }
21
- shouldComponentUpdate(nextProps, nextState) {
22
- return nextState !== this.state || nextProps !== this.props;
23
- }
24
- componentWillUnmount() {
25
- if (this.listener) {
26
- this.listener();
27
- this.listener = null;
28
- }
29
- }
30
- update(nextState, ownProps = this.props) {
31
- this.setState(selection(nextState, ownProps));
32
- }
33
- render() {
34
- return <WrappedComponent {...this.props} {...this.state} />;
35
- }
36
- };
37
- };
38
- };
39
- };
40
- //#endregion
41
- export { connect };
42
-
43
- //# sourceMappingURL=connect.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.mjs","names":[],"sources":["../src/connect.tsx"],"sourcesContent":["import { Component, type ComponentType } from \"react\";\nimport type { State } from \"./State\";\nimport type { Subtract } from \"./types\";\n\nexport const connect = <StateInstance extends State<any>>(\n state: StateInstance,\n) => {\n type ScopedState = ReturnType<StateInstance[\"getSnapshot\"]>;\n return <\n SelectorFunction extends (\n state: ScopedState,\n ownProps: any,\n ) => Record<string, any>,\n >(\n selection: SelectorFunction,\n ) => {\n type Selection = ReturnType<SelectorFunction>;\n return <ComponentProps extends Selection>(\n WrappedComponent: ComponentType<ComponentProps>,\n ): ComponentType<Subtract<ComponentProps, Selection>> => {\n type OwnProps = Subtract<ComponentProps, Selection>;\n return class GalenaComponent extends Component<OwnProps, Selection> {\n override state: any;\n private listener: (() => void) | null = null;\n constructor(props: OwnProps) {\n super(props);\n this.update = this.update.bind(this);\n this.state = selection(state.getSnapshot(), this.props);\n }\n\n static displayName = `GalenaComponent(${\n (WrappedComponent.displayName ?? WrappedComponent.name) || \"Component\"\n })`;\n\n public override componentDidMount() {\n this.listener = state.subscribe(state => this.update(state));\n }\n\n public override UNSAFE_componentWillReceiveProps(nextProps: OwnProps) {\n if (nextProps !== this.props) {\n this.update(state.getSnapshot(), nextProps);\n }\n }\n\n public override shouldComponentUpdate(\n nextProps: OwnProps,\n nextState: Selection,\n ) {\n return nextState !== this.state || nextProps !== this.props;\n }\n\n public override componentWillUnmount() {\n if (this.listener) {\n this.listener();\n this.listener = null;\n }\n }\n\n private update(nextState: ScopedState, ownProps = this.props) {\n this.setState(selection(nextState, ownProps));\n }\n\n public override render() {\n return <WrappedComponent {...this.props} {...this.state} />;\n }\n };\n };\n };\n};\n"],"mappings":";;AAIA,MAAa,WACX,UACG;AAEH,SAME,cACG;AAEH,UACE,qBACuD;AAEvD,UAAO,MAAM,wBAAwB,UAA+B;IAClE;IACA,WAAwC;IACxC,YAAY,OAAiB;AAC3B,WAAM,MAAM;AACZ,UAAK,SAAS,KAAK,OAAO,KAAK,KAAK;AACpC,UAAK,QAAQ,UAAU,MAAM,aAAa,EAAE,KAAK,MAAM;;IAGzD,OAAO,cAAc,oBAClB,iBAAiB,eAAe,iBAAiB,SAAS,YAC5D;IAED,oBAAoC;AAClC,UAAK,WAAW,MAAM,WAAU,UAAS,KAAK,OAAO,MAAM,CAAC;;IAG9D,iCAAiD,WAAqB;AACpE,SAAI,cAAc,KAAK,MACrB,MAAK,OAAO,MAAM,aAAa,EAAE,UAAU;;IAI/C,sBACE,WACA,WACA;AACA,YAAO,cAAc,KAAK,SAAS,cAAc,KAAK;;IAGxD,uBAAuC;AACrC,SAAI,KAAK,UAAU;AACjB,WAAK,UAAU;AACf,WAAK,WAAW;;;IAIpB,OAAe,WAAwB,WAAW,KAAK,OAAO;AAC5D,UAAK,SAAS,UAAU,WAAW,SAAS,CAAC;;IAG/C,SAAyB;AACvB,YAAO,CAAC,qBAAqB,KAAK,WAAW,KAAK"}
@@ -1,47 +0,0 @@
1
- const require_commonHooks = require("./commonHooks.cjs");
2
- //#region src/createUseState.ts
3
- /**
4
- * Create Use State
5
- *
6
- * A reuseable `State` consumer/creator for your react components.
7
- * This hook can accept an exising instance of `State` and return
8
- * a hook for deriving reactive state and updaters fn's for your components
9
- *
10
- * ```typescript
11
- * import { State, createUseState } from "@figliolia/galena";
12
- *
13
- * const myState = new State("<some-value>");
14
- *
15
- * export const useMyState = createUseState(myState);
16
- *
17
- * // In your components
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useMyState(
20
- * // optional selector function
21
- * );
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can accept an optional selector function for deriving
30
- * new values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, createUseState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- * const useMyState = createUseState(myState);
37
- *
38
- * const eight = useMyState(myState, state => deeply.nested.data * 2);
39
- * ```
40
- */
41
- const createUseState = (value) => {
42
- return (selector = ((value) => value)) => {
43
- return require_commonHooks.useStateHookAPI(value, require_commonHooks.useStableSelector(selector));
44
- };
45
- };
46
- //#endregion
47
- exports.createUseState = createUseState;
@@ -1,46 +0,0 @@
1
- import { NonFunction, Setter } from "./types.cjs";
2
- import { State } from "./State.cjs";
3
-
4
- //#region src/createUseState.d.ts
5
- /**
6
- * Create Use State
7
- *
8
- * A reuseable `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` and return
10
- * a hook for deriving reactive state and updaters fn's for your components
11
- *
12
- * ```typescript
13
- * import { State, createUseState } from "@figliolia/galena";
14
- *
15
- * const myState = new State("<some-value>");
16
- *
17
- * export const useMyState = createUseState(myState);
18
- *
19
- * // In your components
20
- * export const MyComponent = () => {
21
- * const [state, setState] = useMyState(
22
- * // optional selector function
23
- * );
24
- *
25
- * return (
26
- * // your jsx
27
- * );
28
- * }
29
- * ```
30
- *
31
- * `useState` can accept an optional selector function for deriving
32
- * new values from a unit of state
33
- *
34
- * ```typescript
35
- * import { State, createUseState } from "@figliolia/galena";
36
- *
37
- * const myState = new State({ deeply: { nested: data: 4 } });
38
- * const useMyState = createUseState(myState);
39
- *
40
- * const eight = useMyState(myState, state => deeply.nested.data * 2);
41
- * ```
42
- */
43
- declare const createUseState: <T>(value: State<T>) => <U = T>(selector?: (value: NonFunction<T>) => U) => readonly [U, (setter: Setter<T>) => void];
44
- //#endregion
45
- export { createUseState };
46
- //# sourceMappingURL=createUseState.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createUseState.d.cts","names":[],"sources":["../src/createUseState.ts"],"mappings":";;;;;;AA0CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,MAAqB,KAAA,EAAO,KAAA,CAAM,CAAA,WACjC,CAAA,EACV,QAAA,IACE,KAAA,EAAO,WAAA,CAAY,CAAA,MAChB,CAAA,eAAC,CAAA,GAAA,MAAA,EAAA,MAAA,CAAA,CAAA"}
@@ -1,46 +0,0 @@
1
- import { NonFunction, Setter } from "./types.mjs";
2
- import { State } from "./State.mjs";
3
-
4
- //#region src/createUseState.d.ts
5
- /**
6
- * Create Use State
7
- *
8
- * A reuseable `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` and return
10
- * a hook for deriving reactive state and updaters fn's for your components
11
- *
12
- * ```typescript
13
- * import { State, createUseState } from "@figliolia/galena";
14
- *
15
- * const myState = new State("<some-value>");
16
- *
17
- * export const useMyState = createUseState(myState);
18
- *
19
- * // In your components
20
- * export const MyComponent = () => {
21
- * const [state, setState] = useMyState(
22
- * // optional selector function
23
- * );
24
- *
25
- * return (
26
- * // your jsx
27
- * );
28
- * }
29
- * ```
30
- *
31
- * `useState` can accept an optional selector function for deriving
32
- * new values from a unit of state
33
- *
34
- * ```typescript
35
- * import { State, createUseState } from "@figliolia/galena";
36
- *
37
- * const myState = new State({ deeply: { nested: data: 4 } });
38
- * const useMyState = createUseState(myState);
39
- *
40
- * const eight = useMyState(myState, state => deeply.nested.data * 2);
41
- * ```
42
- */
43
- declare const createUseState: <T>(value: State<T>) => <U = T>(selector?: (value: NonFunction<T>) => U) => readonly [U, (setter: Setter<T>) => void];
44
- //#endregion
45
- export { createUseState };
46
- //# sourceMappingURL=createUseState.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createUseState.d.mts","names":[],"sources":["../src/createUseState.ts"],"mappings":";;;;;;AA0CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,MAAqB,KAAA,EAAO,KAAA,CAAM,CAAA,WACjC,CAAA,EACV,QAAA,IACE,KAAA,EAAO,WAAA,CAAY,CAAA,MAChB,CAAA,eAAC,CAAA,GAAA,MAAA,EAAA,MAAA,CAAA,CAAA"}
@@ -1,49 +0,0 @@
1
- import { useStableSelector, useStateHookAPI } from "./commonHooks.mjs";
2
- //#region src/createUseState.ts
3
- /**
4
- * Create Use State
5
- *
6
- * A reuseable `State` consumer/creator for your react components.
7
- * This hook can accept an exising instance of `State` and return
8
- * a hook for deriving reactive state and updaters fn's for your components
9
- *
10
- * ```typescript
11
- * import { State, createUseState } from "@figliolia/galena";
12
- *
13
- * const myState = new State("<some-value>");
14
- *
15
- * export const useMyState = createUseState(myState);
16
- *
17
- * // In your components
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useMyState(
20
- * // optional selector function
21
- * );
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can accept an optional selector function for deriving
30
- * new values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, createUseState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- * const useMyState = createUseState(myState);
37
- *
38
- * const eight = useMyState(myState, state => deeply.nested.data * 2);
39
- * ```
40
- */
41
- const createUseState = (value) => {
42
- return (selector = ((value) => value)) => {
43
- return useStateHookAPI(value, useStableSelector(selector));
44
- };
45
- };
46
- //#endregion
47
- export { createUseState };
48
-
49
- //# sourceMappingURL=createUseState.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createUseState.mjs","names":[],"sources":["../src/createUseState.ts"],"sourcesContent":["import { useStableSelector, useStateHookAPI } from \"./commonHooks\";\nimport type { State } from \"./State\";\nimport type { NonFunction } from \"./types\";\n\n/**\n * Create Use State\n *\n * A reuseable `State` consumer/creator for your react components.\n * This hook can accept an exising instance of `State` and return\n * a hook for deriving reactive state and updaters fn's for your components\n *\n * ```typescript\n * import { State, createUseState } from \"@figliolia/galena\";\n *\n * const myState = new State(\"<some-value>\");\n *\n * export const useMyState = createUseState(myState);\n *\n * // In your components\n * export const MyComponent = () => {\n * const [state, setState] = useMyState(\n * // optional selector function\n * );\n *\n * return (\n * // your jsx\n * );\n * }\n * ```\n *\n * `useState` can accept an optional selector function for deriving\n * new values from a unit of state\n *\n * ```typescript\n * import { State, createUseState } from \"@figliolia/galena\";\n *\n * const myState = new State({ deeply: { nested: data: 4 } });\n * const useMyState = createUseState(myState);\n *\n * const eight = useMyState(myState, state => deeply.nested.data * 2);\n * ```\n */\nexport const createUseState = <T>(value: State<T>) => {\n return <U = T>(\n selector = ((value: NonFunction<T>) => value) as (\n value: NonFunction<T>,\n ) => U,\n ) => {\n const stableSelector = useStableSelector(selector);\n return useStateHookAPI(value, stableSelector);\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,kBAAqB,UAAoB;AACpD,SACE,aAAa,UAA0B,WAGpC;AAEH,SAAO,gBAAgB,OADA,kBAAkB,SAAS,CACL"}
package/dist/useState.cjs DELETED
@@ -1,45 +0,0 @@
1
- const require_commonHooks = require("./commonHooks.cjs");
2
- const require_State = require("./State.cjs");
3
- let react = require("react");
4
- //#region src/useState.ts
5
- /**
6
- * Use State
7
- *
8
- * A `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` or
10
- * a stateful value and return reactive state and updaters
11
- * for your components
12
- *
13
- * ```typescript
14
- * import { State, useState } from "@figliolia/galena";
15
- *
16
- * const myState = new State("<some-value>");
17
- *
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useState(myState);
20
- * // or useState can be used a standalone replacement for React's useState
21
- * const [state, setState] = useState("<some-value>");
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can also accept an optional selector function for deriving
30
- * values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, useState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- *
37
- * const eight = useState(myState, state => deeply.nested.data * 2);
38
- * ```
39
- */
40
- const useState = (value, selector = ((value) => value)) => {
41
- const stableSelector = require_commonHooks.useStableSelector(selector);
42
- return require_commonHooks.useStateHookAPI((0, react.useMemo)(() => value instanceof require_State.State ? value : new require_State.State(value), [value]), stableSelector);
43
- };
44
- //#endregion
45
- exports.useState = useState;
@@ -1,43 +0,0 @@
1
- import { NonFunction, Setter } from "./types.cjs";
2
- import { State } from "./State.cjs";
3
-
4
- //#region src/useState.d.ts
5
- /**
6
- * Use State
7
- *
8
- * A `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` or
10
- * a stateful value and return reactive state and updaters
11
- * for your components
12
- *
13
- * ```typescript
14
- * import { State, useState } from "@figliolia/galena";
15
- *
16
- * const myState = new State("<some-value>");
17
- *
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useState(myState);
20
- * // or useState can be used a standalone replacement for React's useState
21
- * const [state, setState] = useState("<some-value>");
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can also accept an optional selector function for deriving
30
- * values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, useState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- *
37
- * const eight = useState(myState, state => deeply.nested.data * 2);
38
- * ```
39
- */
40
- declare const useState: <T, U = T>(value: NonFunction<T> | State<T>, selector?: (value: NonFunction<T>) => U) => readonly [U, (setter: Setter<T>) => void];
41
- //#endregion
42
- export { useState };
43
- //# sourceMappingURL=useState.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useState.d.cts","names":[],"sources":["../src/useState.ts"],"mappings":";;;;;;AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,QAAA,UAAmB,CAAA,EAC9B,KAAA,EAAO,WAAA,CAAY,CAAA,IAAK,KAAA,CAAM,CAAA,GAC9B,QAAA,IAAkD,KAAA,EAAO,WAAA,CAAY,CAAA,MAAO,CAAA,eAAC,CAAA,GAAA,MAAA,EAAA,MAAA,CAAA,CAAA"}
@@ -1,43 +0,0 @@
1
- import { NonFunction, Setter } from "./types.mjs";
2
- import { State } from "./State.mjs";
3
-
4
- //#region src/useState.d.ts
5
- /**
6
- * Use State
7
- *
8
- * A `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` or
10
- * a stateful value and return reactive state and updaters
11
- * for your components
12
- *
13
- * ```typescript
14
- * import { State, useState } from "@figliolia/galena";
15
- *
16
- * const myState = new State("<some-value>");
17
- *
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useState(myState);
20
- * // or useState can be used a standalone replacement for React's useState
21
- * const [state, setState] = useState("<some-value>");
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can also accept an optional selector function for deriving
30
- * values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, useState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- *
37
- * const eight = useState(myState, state => deeply.nested.data * 2);
38
- * ```
39
- */
40
- declare const useState: <T, U = T>(value: NonFunction<T> | State<T>, selector?: (value: NonFunction<T>) => U) => readonly [U, (setter: Setter<T>) => void];
41
- //#endregion
42
- export { useState };
43
- //# sourceMappingURL=useState.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useState.d.mts","names":[],"sources":["../src/useState.ts"],"mappings":";;;;;;AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,QAAA,UAAmB,CAAA,EAC9B,KAAA,EAAO,WAAA,CAAY,CAAA,IAAK,KAAA,CAAM,CAAA,GAC9B,QAAA,IAAkD,KAAA,EAAO,WAAA,CAAY,CAAA,MAAO,CAAA,eAAC,CAAA,GAAA,MAAA,EAAA,MAAA,CAAA,CAAA"}
package/dist/useState.mjs DELETED
@@ -1,47 +0,0 @@
1
- import { useStableSelector, useStateHookAPI } from "./commonHooks.mjs";
2
- import { State } from "./State.mjs";
3
- import { useMemo } from "react";
4
- //#region src/useState.ts
5
- /**
6
- * Use State
7
- *
8
- * A `State` consumer/creator for your react components.
9
- * This hook can accept an exising instance of `State` or
10
- * a stateful value and return reactive state and updaters
11
- * for your components
12
- *
13
- * ```typescript
14
- * import { State, useState } from "@figliolia/galena";
15
- *
16
- * const myState = new State("<some-value>");
17
- *
18
- * export const MyComponent = () => {
19
- * const [state, setState] = useState(myState);
20
- * // or useState can be used a standalone replacement for React's useState
21
- * const [state, setState] = useState("<some-value>");
22
- *
23
- * return (
24
- * // your jsx
25
- * );
26
- * }
27
- * ```
28
- *
29
- * `useState` can also accept an optional selector function for deriving
30
- * values from a unit of state
31
- *
32
- * ```typescript
33
- * import { State, useState } from "@figliolia/galena";
34
- *
35
- * const myState = new State({ deeply: { nested: data: 4 } });
36
- *
37
- * const eight = useState(myState, state => deeply.nested.data * 2);
38
- * ```
39
- */
40
- const useState = (value, selector = ((value) => value)) => {
41
- const stableSelector = useStableSelector(selector);
42
- return useStateHookAPI(useMemo(() => value instanceof State ? value : new State(value), [value]), stableSelector);
43
- };
44
- //#endregion
45
- export { useState };
46
-
47
- //# sourceMappingURL=useState.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useState.mjs","names":[],"sources":["../src/useState.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useStableSelector, useStateHookAPI } from \"./commonHooks\";\nimport { State } from \"./State\";\nimport type { NonFunction } from \"./types\";\n\n/**\n * Use State\n *\n * A `State` consumer/creator for your react components.\n * This hook can accept an exising instance of `State` or\n * a stateful value and return reactive state and updaters\n * for your components\n *\n * ```typescript\n * import { State, useState } from \"@figliolia/galena\";\n *\n * const myState = new State(\"<some-value>\");\n *\n * export const MyComponent = () => {\n * const [state, setState] = useState(myState);\n * // or useState can be used a standalone replacement for React's useState\n * const [state, setState] = useState(\"<some-value>\");\n *\n * return (\n * // your jsx\n * );\n * }\n * ```\n *\n * `useState` can also accept an optional selector function for deriving\n * values from a unit of state\n *\n * ```typescript\n * import { State, useState } from \"@figliolia/galena\";\n *\n * const myState = new State({ deeply: { nested: data: 4 } });\n *\n * const eight = useState(myState, state => deeply.nested.data * 2);\n * ```\n */\nexport const useState = <T, U = T>(\n value: NonFunction<T> | State<T>,\n selector = ((value: NonFunction<T>) => value) as (value: NonFunction<T>) => U,\n) => {\n const stableSelector = useStableSelector(selector);\n const readable = useMemo(\n () => (value instanceof State ? value : new State(value)),\n [value],\n );\n return useStateHookAPI(readable, stableSelector);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,YACX,OACA,aAAa,UAA0B,WACpC;CACH,MAAM,iBAAiB,kBAAkB,SAAS;AAKlD,QAAO,gBAJU,cACR,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,MAAM,EACxD,CAAC,MAAM,CACR,EACgC,eAAe"}