How to use the @politie/sherlock._internal.symbols function in @politie/sherlock

To help you get started, we’ve selected a few @politie/sherlock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github politie / sherlock / extensions / sherlock-utils / src / derivable-cache.spec.ts View on Github external
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);
    });
github politie / sherlock / extensions / sherlock-utils / src / state.spec.ts View on Github external
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;
    });
});
github politie / sherlock / extensions / sherlock-rxjs / rxjs.spec.ts View on Github external
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;
        });
github politie / sherlock / extensions / sherlock-rxjs / rxjs.spec.ts View on Github external
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;
        });
github politie / sherlock / extensions / sherlock-utils / src / control-flow.ts View on Github external
};
        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) &&