How to use the @politie/sherlock.constant 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-proxy / proxy.spec.ts View on Github external
it('should support for ... of (ES5 style)', () => {
                const obj = new LetterCount().$create(constant('also pointless')) as any;
                const result = [];
                // tslint:disable-next-line:prefer-for-of
                for (let i = 0; i < obj.length; i++) {
                    result.push(obj[i].$value);
                }
                expect(result).to.deep.equal('also pointless'.split(''));
            });
github politie / sherlock / extensions / sherlock-utils / src / derivable-cache.spec.ts View on Github external
it('should reuse proxies as much as possible', () => {
        const cache = derivableCache({ derivableFactory: constant });
        const proxy1 = cache('abc');
        const proxy2 = cache('abc');

        // Cannot remember proxies without connection, because we don't know when to evict them.
        expect(proxy2).to.not.equal(proxy1);

        proxy1.autoCache().get();

        // But when connected we can automatically reuse proxies when using simple keys.
        expect(cache('abc')).to.equal(proxy1);

        // Not possible when using derivables as input of course
        expect(cache(constant('abc'))).to.not.equal(proxy1);
    });
github politie / sherlock / extensions / sherlock-utils / src / lift.spec.ts View on Github external
it('should unwrap parameters before handing them over to the provided function', () => {
        const a$ = constant('a');
        const b$ = constant('b');
        const n$ = constant(123);

        const f = lift(monadic);
        expect(f(a$).get()).to.equal('monadic (a)');
        expect(f('a').get()).to.equal('monadic (a)');

        const g = lift(dyadic);
        expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
        expect(g('a', n$).get()).to.equal('dyadic (a,123)');

        const h = lift(triadic);
        expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
        expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
    });
});
github politie / sherlock / extensions / sherlock-utils / src / lift.spec.ts View on Github external
it('should unwrap parameters before handing them over to the provided function', () => {
        const a$ = constant('a');
        const b$ = constant('b');
        const n$ = constant(123);

        const f = lift(monadic);
        expect(f(a$).get()).to.equal('monadic (a)');
        expect(f('a').get()).to.equal('monadic (a)');

        const g = lift(dyadic);
        expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
        expect(g('a', n$).get()).to.equal('dyadic (a,123)');

        const h = lift(triadic);
        expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
        expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
    });
});
github politie / sherlock / extensions / sherlock-proxy / proxy.spec.ts View on Github external
it('should not be settable when the target is not an Atom', () => {
                const pd = new ProxyDescriptor();
                pd.$target = constant('abc');
                expect(() => pd.$targetValue = 'def').to.throw();
            });
github politie / sherlock / extensions / sherlock-proxy / proxy.spec.ts View on Github external
it('should not be settable when the target is not an Atom', () => {
                const px = new ProxyDescriptor().$create(constant('abc'));
                expect(() => px.$value = 'def').to.throw();
            });
github politie / sherlock / extensions / sherlock-proxy / proxy.spec.ts View on Github external
it('should be possible to override the default $pluck behavior', () => {
                const pd = new ProxyDescriptor();
                pd.$pluck = function (this: ProxyDescriptor, prop: string | number) {
                    return this.$create(this.$target.map(v => (v + ' ' + prop).trim()), extendExpression(this.$expression, prop));
                };
                const px = pd.$create(constant('')) as any;
                expect(px.this.is.awkward.in.more.than[10].ways.$value).to.equal('this is awkward in more than 10 ways');
            });
github politie / sherlock / extensions / sherlock-utils / src / lift.spec.ts View on Github external
it('should unwrap parameters before handing them over to the provided function', () => {
        const a$ = constant('a');
        const b$ = constant('b');
        const n$ = constant(123);

        const f = lift(monadic);
        expect(f(a$).get()).to.equal('monadic (a)');
        expect(f('a').get()).to.equal('monadic (a)');

        const g = lift(dyadic);
        expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
        expect(g('a', n$).get()).to.equal('dyadic (a,123)');

        const h = lift(triadic);
        expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
        expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
    });
});
github politie / sherlock / extensions / sherlock-utils / src / derivable-cache.spec.ts View on Github external
        const derivableFactory = spy((v: number) => constant(v));
        const identityCache = derivableCache({ derivableFactory });
github politie / sherlock / extensions / sherlock-utils / src / derivable-cache.spec.ts View on Github external
            derivableFactory = spy((k: string) => constant('result from ' + k));
            resultCache = derivableCache({ derivableFactory });