-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
// This module "extends" ef.js with a helper function named `map`
import { derived, isReactive, type ReactiveOrStatic } from "../../src/ef.js";
export * from "../../src/ef.js";
/**
* Applies function `f` for `x` when `x` is not `ReactiveValue`, otherwise
* Returns a Derived that value is a result of `f(x.get())`.
*
* Convenient helper to dealing with `ReactiveOrStatic`.
* Useful for composing.
*/
export function map<T, P>(
x: ReactiveOrStatic<T>,
f: (x: T) => P,
): ReactiveOrStatic<P> {
if (isReactive(x)) {
return derived(() => f(x.get()));
}
return f(x);
}