chem-rx 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -247,18 +247,18 @@ function Counter() {
247
247
  <button onClick={() => count$.set('inner', count + 2)}>one up</button> ...
248
248
  ```
249
249
 
250
- ### hydrateAtoms
250
+ ### useHydrateAtoms
251
251
 
252
252
  With SSR, your atoms will likely need to be properly hydrated to prevent
253
- server/client mismatches. You can use `hydrateAtoms` as a simple solution for
253
+ server/client mismatches. You can use `useHydrateAtoms` as a simple solution for
254
254
  seeding your client-side Atoms with the correct data.
255
255
 
256
256
  ```
257
- import { Atom, useAtom, hydrateAtoms } from 'chem-rx'
257
+ import { Atom, useAtom, useHydrateAtoms } from 'chem-rx'
258
258
 
259
259
  const count$ = Atom(0)
260
260
  const CounterPage = ({ countFromServer }) => {
261
- hydrateAtoms([[count$, countFromServer]])
261
+ useHydrateAtoms([[count$, countFromServer]])
262
262
  const count = useAtom(count$)
263
263
  // count would be the value of `countFromServer`, not 0.
264
264
  }
package/dist/index.cjs.js CHANGED
@@ -254,19 +254,21 @@ function useSelectAtom(atom, key) {
254
254
  return value;
255
255
  }
256
256
 
257
- function hydrateAtoms(values) {
258
- for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
259
- var _step$value = _step.value,
260
- atom = _step$value[0],
261
- value = _step$value[1];
262
- atom._behavior$.next(value);
263
- }
257
+ function useHydrateAtoms(values) {
258
+ react.useEffect(function () {
259
+ for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
260
+ var _step$value = _step.value,
261
+ atom = _step$value[0],
262
+ value = _step$value[1];
263
+ atom._behavior$.next(value);
264
+ }
265
+ }, []);
264
266
  }
265
267
 
266
268
  function Signal() {}
267
269
 
268
270
  exports.Atom = Atom;
269
271
  exports.Signal = Signal;
270
- exports.hydrateAtoms = hydrateAtoms;
271
272
  exports.useAtom = useAtom;
273
+ exports.useHydrateAtoms = useHydrateAtoms;
272
274
  exports.useSelectAtom = useSelectAtom;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Atom } from "./Atom";
2
2
  export { useAtom } from "./useAtom";
3
3
  export { useSelectAtom } from "./useSelectAtom";
4
- export { hydrateAtoms } from "./hydrateAtoms";
4
+ export { useHydrateAtoms } from "./useHydrateAtoms";
5
5
  export { Signal } from "./Signal";
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -252,21 +252,23 @@ var chemicalRx = (function (exports, rxjs, react) {
252
252
  return value;
253
253
  }
254
254
 
255
- function hydrateAtoms(values) {
256
- for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
257
- var _step$value = _step.value,
258
- atom = _step$value[0],
259
- value = _step$value[1];
260
- atom._behavior$.next(value);
261
- }
255
+ function useHydrateAtoms(values) {
256
+ react.useEffect(function () {
257
+ for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
258
+ var _step$value = _step.value,
259
+ atom = _step$value[0],
260
+ value = _step$value[1];
261
+ atom._behavior$.next(value);
262
+ }
263
+ }, []);
262
264
  }
263
265
 
264
266
  function Signal() {}
265
267
 
266
268
  exports.Atom = Atom;
267
269
  exports.Signal = Signal;
268
- exports.hydrateAtoms = hydrateAtoms;
269
270
  exports.useAtom = useAtom;
271
+ exports.useHydrateAtoms = useHydrateAtoms;
270
272
  exports.useSelectAtom = useSelectAtom;
271
273
 
272
274
  return exports;
package/dist/index.js CHANGED
@@ -176,12 +176,14 @@ function useSelectAtom(atom, key) {
176
176
  return value;
177
177
  }
178
178
 
179
- function hydrateAtoms(values) {
180
- for (const [atom, value] of values) {
181
- atom._behavior$.next(value);
182
- }
179
+ function useHydrateAtoms(values) {
180
+ useEffect(() => {
181
+ for (const [atom, value] of values) {
182
+ atom._behavior$.next(value);
183
+ }
184
+ }, []);
183
185
  }
184
186
 
185
187
  function Signal() {}
186
188
 
187
- export { Atom, Signal, hydrateAtoms, useAtom, useSelectAtom };
189
+ export { Atom, Signal, useAtom, useHydrateAtoms, useSelectAtom };
@@ -0,0 +1,3 @@
1
+ import { BaseAtom } from "./Atom";
2
+ export declare function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
3
+ //# sourceMappingURL=useHydrateAtoms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAMtE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chem-rx",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "react state primitives powered by rx.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Atom } from "./Atom";
2
2
  export { useAtom } from "./useAtom";
3
3
  export { useSelectAtom } from "./useSelectAtom";
4
- export { hydrateAtoms } from "./hydrateAtoms";
4
+ export { useHydrateAtoms } from "./useHydrateAtoms";
5
5
  export { Signal } from "./Signal";
@@ -0,0 +1,10 @@
1
+ import { useEffect } from "react";
2
+ import { BaseAtom } from "./Atom";
3
+
4
+ export function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
5
+ useEffect(() => {
6
+ for (const [atom, value] of values) {
7
+ atom._behavior$.next(value);
8
+ }
9
+ }, []);
10
+ }
@@ -1,3 +0,0 @@
1
- import { BaseAtom } from "./Atom";
2
- export declare function hydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
3
- //# sourceMappingURL=hydrateAtoms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hydrateAtoms.d.ts","sourceRoot":"","sources":["../src/hydrateAtoms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAInE"}
@@ -1,7 +0,0 @@
1
- import { BaseAtom } from "./Atom";
2
-
3
- export function hydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
4
- for (const [atom, value] of values) {
5
- atom._behavior$.next(value);
6
- }
7
- }