Skip to content

Commit

Permalink
feat: support functions in array parameters to when
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Nov 13, 2024
1 parent 8f5da7a commit 3ee80aa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/when.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isObservable } from './globals';
import { computeSelector, isObservableValueReady } from './helpers';
import { isArray, isPromise } from './is';
import { isArray, isFunction, isPromise } from './is';
import type { ObserveEvent, Selector } from './observableInterfaces';
import { observe } from './observe';

Expand Down Expand Up @@ -29,10 +29,13 @@ function _when<T, T2>(predicate: Selector<T> | Selector<T>[], effect?: (value: T
let isOk: any = true;
if (isArray(ret)) {
for (let i = 0; i < ret.length; i++) {
if (isObservable(ret[i])) {
ret[i] = computeSelector(ret[i]);
let item = ret[i];
if (isObservable(item)) {
item = computeSelector(item);
} else if (isFunction(item)) {
item = item();
}
isOk = isOk && !!(checkReady ? isObservableValueReady(ret[i]) : ret[i]);
isOk = isOk && !!(checkReady ? isObservableValueReady(item) : item);
}
} else {
isOk = checkReady ? isObservableValueReady(ret) : ret;
Expand Down

0 comments on commit 3ee80aa

Please sign in to comment.