@homebound/beam 2.244.4 → 2.245.0
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,2 +1,2 @@
|
|
|
1
1
|
/** Evaluates a computed function `fn` to a regular value and triggers a re-render whenever it changes. */
|
|
2
|
-
export declare function useComputed<T>(fn: () => T, deps: readonly any[]): T;
|
|
2
|
+
export declare function useComputed<T>(fn: (prev: T | undefined) => T, deps: readonly any[]): T;
|
|
@@ -29,9 +29,9 @@ function useComputed(fn, deps) {
|
|
|
29
29
|
// If deps has changed, we're already re-running, so don't trigger a 2nd one
|
|
30
30
|
current.hasRan = false;
|
|
31
31
|
current.runner = (0, mobx_1.autorun)(() => {
|
|
32
|
-
// Always eval fn() (even on 1st render) to register our observable.
|
|
33
|
-
const newValue = fn();
|
|
34
32
|
const { value: oldValue, hasRan: oldHasRun } = current;
|
|
33
|
+
// Always eval fn() (even on 1st render) to register our observable.
|
|
34
|
+
const newValue = fn(oldValue);
|
|
35
35
|
current.value = newValue;
|
|
36
36
|
current.hasRan = true;
|
|
37
37
|
// Only trigger a re-render if this is not the 1st autorun. Note
|
|
@@ -51,7 +51,7 @@ function useComputed(fn, deps) {
|
|
|
51
51
|
// accept running the eval fn twice (here to get the value for the 1st render,
|
|
52
52
|
// and again for mobx to watch what observables we touch).
|
|
53
53
|
if (!ref.current.hasRan) {
|
|
54
|
-
ref.current.value = fn();
|
|
54
|
+
ref.current.value = fn(undefined);
|
|
55
55
|
}
|
|
56
56
|
// We can use `!` here b/c we know that `autorun` set current
|
|
57
57
|
return ref.current.value;
|