@fbltd/async 1.0.29 → 1.0.31

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,26 +1,25 @@
1
- import React, { createElement, useEffect, useState } from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { observationState } from "../../../observe.state.js";
3
3
  import { usePromise } from "./utils.js";
4
- function Reactive(fn) {
4
+ export function Reactive(fn) {
5
5
  return React.memo((props) => {
6
- const [key, setKey] = useState(Math.random());
6
+ const [key, setKey] = useState(false);
7
7
  const abortPromise = usePromise();
8
8
  useEffect(() => abortPromise.resolve, []);
9
9
  observationState.isObserved = true;
10
- useEffect(() => {
11
- const deps = observationState.getDeps();
12
- observationState.isObserved = false;
13
- if (!deps.size)
14
- return;
10
+ const jsx = fn(props);
11
+ const deps = observationState.getDeps();
12
+ observationState.isObserved = false;
13
+ if (deps.size) {
15
14
  let prom = [abortPromise.promise];
16
15
  deps.forEach(d => prom.push(d.next()));
17
16
  Promise.race(prom)
18
17
  .then(() => {
19
18
  if (abortPromise.isFulfilled)
20
19
  return;
21
- setKey(Math.random());
20
+ setKey(!key);
22
21
  });
23
- }, [key, props]);
24
- return createElement(fn, props);
22
+ }
23
+ return jsx;
25
24
  });
26
25
  }
@@ -1 +1,2 @@
1
- export {};
1
+ import { FunctionComponent, NamedExoticComponent } from "react";
2
+ export declare function Reactive<P extends object>(fn: FunctionComponent<P>): NamedExoticComponent<P>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/async",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Miscellaneous async utils",
5
5
  "homepage": "https://github.com/GlennMiller1991/async",
6
6
  "type": "module",