This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

36 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-04-02 02:24:13 +03:00
import AnimatedValue from '../core/InternalAnimatedValue';
import { createAnimatedSet as set } from '../core/AnimatedSet';
import { createAnimatedCall as call } from '../core/AnimatedCall';
import { createAnimatedAlways as always } from '../core/AnimatedAlways';
import { createAnimatedCond as cond } from '../core/AnimatedCond';
/**
* evaluate given node and notify children
* @param node - node to be evaluated
* @param input - nodes (or one node) representing values which states input for node.
* @param callback - after callback
*/
export function evaluateOnce(node, input = [], callback) {
if (!Array.isArray(input)) {
input = [input];
}
const done = new AnimatedValue(0);
const evalNode = cond(done, 0, call([node, set(done, 1)], () => {
callback && callback();
for (let i = 0; i < input.length; i++) {
input[i].__removeChild(alwaysNode);
alwaysNode.__detach();
}
}));
const alwaysNode = always(evalNode);
for (let i = 0; i < input.length; i++) {
input[i].__addChild(alwaysNode);
alwaysNode.__attach();
}
}
//# sourceMappingURL=evaluateOnce.js.map