chem-rx 0.0.8 → 0.0.9

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/dist/index.cjs.js CHANGED
@@ -254,17 +254,16 @@ function useSelectAtom(atom, key) {
254
254
  return value;
255
255
  }
256
256
 
257
- function useHydrateAtoms(values) {
258
- react.useEffect(function () {
259
- hydrateAtoms(values);
260
- }, []);
261
- }
257
+ var hydratedAtomsSet = new WeakSet();
262
258
  function hydrateAtoms(values) {
263
259
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
264
260
  var _step$value = _step.value,
265
261
  atom = _step$value[0],
266
262
  value = _step$value[1];
267
- atom._behavior$.next(value);
263
+ if (!hydratedAtomsSet.has(atom)) {
264
+ hydratedAtomsSet.add(atom);
265
+ atom._behavior$.next(value);
266
+ }
268
267
  }
269
268
  }
270
269
 
@@ -274,5 +273,4 @@ exports.Atom = Atom;
274
273
  exports.Signal = Signal;
275
274
  exports.hydrateAtoms = hydrateAtoms;
276
275
  exports.useAtom = useAtom;
277
- exports.useHydrateAtoms = useHydrateAtoms;
278
276
  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, useHydrateAtoms } from "./useHydrateAtoms";
4
+ export { hydrateAtoms } 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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClE,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,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -252,17 +252,16 @@ var chemicalRx = (function (exports, rxjs, react) {
252
252
  return value;
253
253
  }
254
254
 
255
- function useHydrateAtoms(values) {
256
- react.useEffect(function () {
257
- hydrateAtoms(values);
258
- }, []);
259
- }
255
+ var hydratedAtomsSet = new WeakSet();
260
256
  function hydrateAtoms(values) {
261
257
  for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
262
258
  var _step$value = _step.value,
263
259
  atom = _step$value[0],
264
260
  value = _step$value[1];
265
- atom._behavior$.next(value);
261
+ if (!hydratedAtomsSet.has(atom)) {
262
+ hydratedAtomsSet.add(atom);
263
+ atom._behavior$.next(value);
264
+ }
266
265
  }
267
266
  }
268
267
 
@@ -272,7 +271,6 @@ var chemicalRx = (function (exports, rxjs, react) {
272
271
  exports.Signal = Signal;
273
272
  exports.hydrateAtoms = hydrateAtoms;
274
273
  exports.useAtom = useAtom;
275
- exports.useHydrateAtoms = useHydrateAtoms;
276
274
  exports.useSelectAtom = useSelectAtom;
277
275
 
278
276
  return exports;
package/dist/index.js CHANGED
@@ -176,17 +176,16 @@ function useSelectAtom(atom, key) {
176
176
  return value;
177
177
  }
178
178
 
179
- function useHydrateAtoms(values) {
180
- useEffect(() => {
181
- hydrateAtoms(values);
182
- }, []);
183
- }
179
+ const hydratedAtomsSet = new WeakSet();
184
180
  function hydrateAtoms(values) {
185
181
  for (const [atom, value] of values) {
186
- atom._behavior$.next(value);
182
+ if (!hydratedAtomsSet.has(atom)) {
183
+ hydratedAtomsSet.add(atom);
184
+ atom._behavior$.next(value);
185
+ }
187
186
  }
188
187
  }
189
188
 
190
189
  function Signal() {}
191
190
 
192
- export { Atom, Signal, hydrateAtoms, useAtom, useHydrateAtoms, useSelectAtom };
191
+ export { Atom, Signal, hydrateAtoms, useAtom, useSelectAtom };
@@ -1,4 +1,3 @@
1
1
  import { BaseAtom } from "./Atom";
2
- export declare function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
3
2
  export declare function hydrateAtoms(values: readonly [BaseAtom<any>, any][]): void;
4
3
  //# sourceMappingURL=useHydrateAtoms.d.ts.map
@@ -1 +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,QAItE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAInE"}
1
+ {"version":3,"file":"useHydrateAtoms.d.ts","sourceRoot":"","sources":["../src/useHydrateAtoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,QAAQ,CAAC;AAIhD,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,QAOnE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chem-rx",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
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, useHydrateAtoms } from "./useHydrateAtoms";
4
+ export { hydrateAtoms } from "./useHydrateAtoms";
5
5
  export { Signal } from "./Signal";
@@ -1,14 +1,13 @@
1
1
  import { useEffect } from "react";
2
- import { BaseAtom } from "./Atom";
2
+ import { BaseAtom, ReadOnlyAtom } from "./Atom";
3
3
 
4
- export function useHydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
5
- useEffect(() => {
6
- hydrateAtoms(values);
7
- }, []);
8
- }
4
+ const hydratedAtomsSet: WeakSet<ReadOnlyAtom<any>> = new WeakSet();
9
5
 
10
6
  export function hydrateAtoms(values: readonly [BaseAtom<any>, any][]) {
11
7
  for (const [atom, value] of values) {
12
- atom._behavior$.next(value);
8
+ if (!hydratedAtomsSet.has(atom)) {
9
+ hydratedAtomsSet.add(atom);
10
+ atom._behavior$.next(value);
11
+ }
13
12
  }
14
13
  }