signalium 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
 
2
- > signalium@1.1.1 build
2
+ > signalium@1.2.1 build
3
3
  > npm run build:esm && npm run build:cjs
4
4
 
5
5
 
6
- > signalium@1.1.1 build:esm
6
+ > signalium@1.2.1 build:esm
7
7
  > tsc
8
8
 
9
9
 
10
- > signalium@1.1.1 build:cjs
10
+ > signalium@1.2.1 build:cjs
11
11
  > tsc --module commonjs --outDir dist/cjs --moduleResolution node
12
12
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # signalium
2
2
 
3
+ ## 1.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - af9216c: Updates runReactiveSafe API to simplify types
8
+
9
+ ## 1.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - a56cc6f: Add runReactiveSafe for running reactive functions safely in React apps
14
+
3
15
  ## 1.1.1
4
16
 
5
17
  ### Patch Changes
@@ -2,4 +2,5 @@ export { ContextProvider } from './provider.js';
2
2
  export { useScope } from './context.js';
3
3
  export { setupReact } from './setup.js';
4
4
  export { useStateSignal } from './state.js';
5
+ export { runReactiveSafe } from './rendering.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useStateSignal = exports.setupReact = exports.useScope = exports.ContextProvider = void 0;
3
+ exports.runReactiveSafe = exports.useStateSignal = exports.setupReact = exports.useScope = exports.ContextProvider = void 0;
4
4
  var provider_js_1 = require("./provider.js");
5
5
  Object.defineProperty(exports, "ContextProvider", { enumerable: true, get: function () { return provider_js_1.ContextProvider; } });
6
6
  var context_js_1 = require("./context.js");
@@ -9,4 +9,6 @@ var setup_js_1 = require("./setup.js");
9
9
  Object.defineProperty(exports, "setupReact", { enumerable: true, get: function () { return setup_js_1.setupReact; } });
10
10
  var state_js_1 = require("./state.js");
11
11
  Object.defineProperty(exports, "useStateSignal", { enumerable: true, get: function () { return state_js_1.useStateSignal; } });
12
+ var rendering_js_1 = require("./rendering.js");
13
+ Object.defineProperty(exports, "runReactiveSafe", { enumerable: true, get: function () { return rendering_js_1.runReactiveSafe; } });
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAAvC,8GAAA,eAAe,OAAA;AACxB,2CAAwC;AAA/B,sGAAA,QAAQ,OAAA;AACjB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,uCAA4C;AAAnC,0GAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAAvC,8GAAA,eAAe,OAAA;AACxB,2CAAwC;AAA/B,sGAAA,QAAQ,OAAA;AACjB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AAEvB,+CAAiD;AAAxC,+GAAA,eAAe,OAAA"}
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Reactive functions can be called anywhere, but React Hooks cannot. When calling reactive functions
3
+ * in code that _may or may not_ be used while rendering, we need to use this function to wrap the
4
+ * call. This will ensure that we will not be in a rendering context when the reactive function is called.
5
+ */
6
+ export declare const runReactiveSafe: <T>(fn: () => T) => T;
1
7
  export declare function isRendering(): boolean;
2
8
  //# sourceMappingURL=rendering.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAcA,wBAAgB,WAAW,YAU1B"}
1
+ {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,MAAM,MAAM,CAAC,KAAG,CAQhD,CAAC;AAEF,wBAAgB,WAAW,YAW1B"}
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runReactiveSafe = void 0;
6
7
  exports.isRendering = isRendering;
7
8
  const react_1 = __importDefault(require("react"));
8
9
  // This is a private React internal that we need to access to check if we are rendering.
@@ -14,9 +15,26 @@ const REACT_INTERNALS = react_1.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WIL
14
15
  react_1.default.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
15
16
  const IS_REACT_18 = !!REACT_INTERNALS.ReactCurrentDispatcher;
16
17
  const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
18
+ let RENDERING_SAFE_MODE_COUNT = 0;
19
+ /**
20
+ * Reactive functions can be called anywhere, but React Hooks cannot. When calling reactive functions
21
+ * in code that _may or may not_ be used while rendering, we need to use this function to wrap the
22
+ * call. This will ensure that we will not be in a rendering context when the reactive function is called.
23
+ */
24
+ const runReactiveSafe = (fn) => {
25
+ RENDERING_SAFE_MODE_COUNT++;
26
+ try {
27
+ return fn();
28
+ }
29
+ finally {
30
+ RENDERING_SAFE_MODE_COUNT--;
31
+ }
32
+ };
33
+ exports.runReactiveSafe = runReactiveSafe;
17
34
  function isRendering() {
18
35
  const dispatcher = IS_REACT_18 ? ReactCurrentDispatcher.current : ReactCurrentDispatcher.H;
19
- return (!!dispatcher &&
36
+ return (RENDERING_SAFE_MODE_COUNT === 0 &&
37
+ !!dispatcher &&
20
38
  // dispatcher can be in a state where it's defined, but all hooks are invalid to call.
21
39
  // Only way we can tell is that if they are invalid, they will all be equal to each other
22
40
  // (e.g. because it's the function that throws an error)
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.js","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":";;;;;AAcA,kCAUC;AAxBD,kDAA0B;AAE1B,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,eAAa,CAAC,kDAAkD;IAChE,eAAa,CAAC,+DAA+D;IAC7E,eAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,WAAW,GAAG,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC;AAC7D,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,SAAgB,WAAW;IACzB,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE3F,OAAO,CACL,CAAC,CAAC,UAAU;QACZ,sFAAsF;QACtF,yFAAyF;QACzF,wDAAwD;QACxD,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,SAAS,CAC7C,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"rendering.js","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":";;;;;;AA+BA,kCAWC;AA1CD,kDAA0B;AAE1B,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,eAAa,CAAC,kDAAkD;IAChE,eAAa,CAAC,+DAA+D;IAC7E,eAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,WAAW,GAAG,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC;AAC7D,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,IAAI,yBAAyB,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAI,EAAW,EAAK,EAAE;IACnD,yBAAyB,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,yBAAyB,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEF,SAAgB,WAAW;IACzB,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE3F,OAAO,CACL,yBAAyB,KAAK,CAAC;QAC/B,CAAC,CAAC,UAAU;QACZ,sFAAsF;QACtF,yFAAyF;QACzF,wDAAwD;QACxD,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,SAAS,CAC7C,CAAC;AACJ,CAAC"}
@@ -2,4 +2,5 @@ export { ContextProvider } from './provider.js';
2
2
  export { useScope } from './context.js';
3
3
  export { setupReact } from './setup.js';
4
4
  export { useStateSignal } from './state.js';
5
+ export { runReactiveSafe } from './rendering.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
@@ -2,4 +2,5 @@ export { ContextProvider } from './provider.js';
2
2
  export { useScope } from './context.js';
3
3
  export { setupReact } from './setup.js';
4
4
  export { useStateSignal } from './state.js';
5
+ export { runReactiveSafe } from './rendering.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Reactive functions can be called anywhere, but React Hooks cannot. When calling reactive functions
3
+ * in code that _may or may not_ be used while rendering, we need to use this function to wrap the
4
+ * call. This will ensure that we will not be in a rendering context when the reactive function is called.
5
+ */
6
+ export declare const runReactiveSafe: <T>(fn: () => T) => T;
1
7
  export declare function isRendering(): boolean;
2
8
  //# sourceMappingURL=rendering.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAcA,wBAAgB,WAAW,YAU1B"}
1
+ {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,MAAM,MAAM,CAAC,KAAG,CAQhD,CAAC;AAEF,wBAAgB,WAAW,YAW1B"}
@@ -8,9 +8,25 @@ const REACT_INTERNALS = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
8
8
  React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
9
9
  const IS_REACT_18 = !!REACT_INTERNALS.ReactCurrentDispatcher;
10
10
  const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
11
+ let RENDERING_SAFE_MODE_COUNT = 0;
12
+ /**
13
+ * Reactive functions can be called anywhere, but React Hooks cannot. When calling reactive functions
14
+ * in code that _may or may not_ be used while rendering, we need to use this function to wrap the
15
+ * call. This will ensure that we will not be in a rendering context when the reactive function is called.
16
+ */
17
+ export const runReactiveSafe = (fn) => {
18
+ RENDERING_SAFE_MODE_COUNT++;
19
+ try {
20
+ return fn();
21
+ }
22
+ finally {
23
+ RENDERING_SAFE_MODE_COUNT--;
24
+ }
25
+ };
11
26
  export function isRendering() {
12
27
  const dispatcher = IS_REACT_18 ? ReactCurrentDispatcher.current : ReactCurrentDispatcher.H;
13
- return (!!dispatcher &&
28
+ return (RENDERING_SAFE_MODE_COUNT === 0 &&
29
+ !!dispatcher &&
14
30
  // dispatcher can be in a state where it's defined, but all hooks are invalid to call.
15
31
  // Only way we can tell is that if they are invalid, they will all be equal to each other
16
32
  // (e.g. because it's the function that throws an error)
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.js","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,KAAa,CAAC,kDAAkD;IAChE,KAAa,CAAC,+DAA+D;IAC7E,KAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,WAAW,GAAG,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC;AAC7D,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,MAAM,UAAU,WAAW;IACzB,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE3F,OAAO,CACL,CAAC,CAAC,UAAU;QACZ,sFAAsF;QACtF,yFAAyF;QACzF,wDAAwD;QACxD,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,SAAS,CAC7C,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"rendering.js","sourceRoot":"","sources":["../../../src/react/rendering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,KAAa,CAAC,kDAAkD;IAChE,KAAa,CAAC,+DAA+D;IAC7E,KAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,WAAW,GAAG,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC;AAC7D,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,IAAI,yBAAyB,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,EAAW,EAAK,EAAE;IACnD,yBAAyB,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,yBAAyB,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,WAAW;IACzB,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE3F,OAAO,CACL,yBAAyB,KAAK,CAAC;QAC/B,CAAC,CAAC,UAAU;QACZ,sFAAsF;QACtF,yFAAyF;QACzF,wDAAwD;QACxD,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,SAAS,CAC7C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalium",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/pzuraq/signalium",
6
6
  "description": "Chain-reactivity at critical mass",
@@ -2,3 +2,5 @@ export { ContextProvider } from './provider.js';
2
2
  export { useScope } from './context.js';
3
3
  export { setupReact } from './setup.js';
4
4
  export { useStateSignal } from './state.js';
5
+
6
+ export { runReactiveSafe } from './rendering.js';
@@ -12,10 +12,28 @@ const REACT_INTERNALS =
12
12
  const IS_REACT_18 = !!REACT_INTERNALS.ReactCurrentDispatcher;
13
13
  const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
14
14
 
15
+ let RENDERING_SAFE_MODE_COUNT = 0;
16
+
17
+ /**
18
+ * Reactive functions can be called anywhere, but React Hooks cannot. When calling reactive functions
19
+ * in code that _may or may not_ be used while rendering, we need to use this function to wrap the
20
+ * call. This will ensure that we will not be in a rendering context when the reactive function is called.
21
+ */
22
+ export const runReactiveSafe = <T>(fn: () => T): T => {
23
+ RENDERING_SAFE_MODE_COUNT++;
24
+
25
+ try {
26
+ return fn();
27
+ } finally {
28
+ RENDERING_SAFE_MODE_COUNT--;
29
+ }
30
+ };
31
+
15
32
  export function isRendering() {
16
33
  const dispatcher = IS_REACT_18 ? ReactCurrentDispatcher.current : ReactCurrentDispatcher.H;
17
34
 
18
35
  return (
36
+ RENDERING_SAFE_MODE_COUNT === 0 &&
19
37
  !!dispatcher &&
20
38
  // dispatcher can be in a state where it's defined, but all hooks are invalid to call.
21
39
  // Only way we can tell is that if they are invalid, they will all be equal to each other