How to use the @politie/sherlock.isDerivable 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 return a Derivable', () => {
                const px = createForObject('Hello');
                const der = px.$derive(v => v);
                expect(isDerivable(der)).to.be.true;
            });
github politie / sherlock / extensions / sherlock-utils / src / struct.ts View on Github external
function deepUnwrap(obj: any): any {
    if (isDerivable(obj)) {
        return obj.get();
    }
    if (Array.isArray(obj)) {
        return obj.map(deepUnwrap);
    }
    if (utils.isPlainObject(obj)) {
        const result = {};
        for (const key of Object.keys(obj)) {
            result[key] = deepUnwrap(obj[key]);
        }
        return result;
    }
    return obj;
}
github politie / sherlock / extensions / sherlock-utils / src / struct.ts View on Github external
export function struct(obj: any) {
    if (isDerivable(obj)) {
        return obj;
    }
    if (!Array.isArray(obj) && !utils.isPlainObject(obj)) {
        throw new Error('"struct" only accepts Derivables, plain Objects and Arrays');
    }
    return derive(deepUnwrap, obj);
}
github politie / sherlock / extensions / sherlock-utils / src / derivable-cache.ts View on Github external
return key => {
        if (!isDerivable(key)) {
            const cacheItem = cache.get(key);
            if (cacheItem) {
                return cacheItem[CACHED_PROXY];
            }
        }

        return lens(descriptor, key);
    };
}