How to use the @tinkoff/utils/function/applyOrReturn function in @tinkoff/utils

To help you get started, we’ve selected a few @tinkoff/utils 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 TinkoffCreditSystems / tinkoff-request / packages / plugin-cache-deduplicate / src / deduplicate.spec.ts View on Github external
it('test plugin shouldExecute', () => {
        const context = new Context();

        expect(applyOrReturn([context], deduplicate({ shouldExecute: false }).shouldExecute)).toBeFalsy();
        expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeTruthy();
        context.setState({ request: { deduplicateCache: false, url: '' } });
        expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeFalsy();
        context.setState({ request: { deduplicateCache: true, url: '' } });
        expect(applyOrReturn([context], deduplicate({ shouldExecute: true }).shouldExecute)).toBeTruthy();
    });
github TinkoffCreditSystems / tinkoff-request / packages / plugin-batch / src / batch.spec.ts View on Github external
it('test shouldExecute', () => {
        let shouldExecute = batch({ makeGroupedRequest }).shouldExecute;

        expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
        shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
        expect(applyOrReturn([context], shouldExecute)).toBeFalsy();

        context.setState({
            request: {
                batchKey: '123',
            },
        });

        expect(applyOrReturn([context], shouldExecute)).toBeTruthy();
    });
github TinkoffCreditSystems / tinkoff-request / packages / plugin-batch / src / batch.spec.ts View on Github external
it('test shouldExecute', () => {
        let shouldExecute = batch({ makeGroupedRequest }).shouldExecute;

        expect(applyOrReturn([context], shouldExecute)).toBeFalsy();
        shouldExecute = batch({ makeGroupedRequest }).shouldExecute;
        expect(applyOrReturn([context], shouldExecute)).toBeFalsy();

        context.setState({
            request: {
                batchKey: '123',
            },
        });

        expect(applyOrReturn([context], shouldExecute)).toBeTruthy();
    });
github TinkoffCreditSystems / tinkoff-request / packages / core / src / context / Context.ts View on Github external
setState(stateOrFunc: Partial) {
        const newState = applyOrReturn([this.state], stateOrFunc);

        if (newState) {
            this.state = {
                ...this.state,
                ...newState,
            };
        }
    }