Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should keep the dependency tree clean', () => {
const a$ = atom(0);
const atoms = [atom('a'), atom('b'), atom('c')];
const cache = derivableCache({
derivableFactory: key => atoms[key + a$.get()],
});
const result = cache(0).autoCache();
result.get();
expect(result[_internal.symbols.dependencies]).to.have.length(1);
});
it('should not call the internal getter more than once', () => {
const a$ = atom(undefined);
const getter = spy(a$ as any as _internal.BaseDerivable, _internal.symbols.internalGetState);
getStateObject(a$);
expect(getter).to.have.been.calledOnce;
a$.setError(undefined);
getStateObject(a$);
expect(getter).to.have.been.calledTwice;
a$.unset();
getStateObject(a$);
expect(getter).to.have.been.calledThrice;
});
});
it('should stop the internal reactor when the Observable is unobserved', () => {
const sub = toObservable(a$).subscribe();
expect(a$[_internal.symbols.observers]).not.to.be.empty;
sub.unsubscribe();
expect(a$[_internal.symbols.observers]).to.be.empty;
});
it('should stop the internal reactor when the Observable is unobserved', () => {
const sub = toObservable(a$).subscribe();
expect(a$[_internal.symbols.observers]).not.to.be.empty;
sub.unsubscribe();
expect(a$[_internal.symbols.observers]).to.be.empty;
});
};
const cleanup = () => {
alreadyStopped = true;
this._baseConnectionStopper = undefined;
};
const mBase = materialize(this.base) as _internal.BaseDerivable>;
const stopper = _internal.Reactor.create(mBase, update, opts, cleanup);
if (!alreadyStopped) {
this._baseConnectionStopper = stopper;
}
super[_internal.symbols.connect]();
}
[_internal.symbols.disconnect]() {
super[_internal.symbols.disconnect]();
this._currentState = unresolved;
if (this._baseConnectionStopper) {
this._baseConnectionStopper();
this._baseConnectionStopper = undefined;
}
}
}
export function controlFlow(base: Derivable, opts?: ControlFlowOptions): Derivable {
return new ControlFlow(base, opts);
}
function shouldBeLive(opts?: PreparedOptions): boolean {
return !opts || !opts.skipFirst &&
(opts.from === undefined || safeUnwrap(opts.from) === true) &&