Home Reference Source Test Repository

buildDocs/applicators/ComposeApplicator.js

import { identity } from 'lodash';
import { Applicator } from './Applicator';
import { resolveFunction } from '../utils';
export class ComposeApplicator extends Applicator {
    constructor(_config = {}) {
        super();
        this._config = _config;
    }
    get post() {
        return this._config.post === true;
    }
    apply({ config: { execute }, value = identity, args, target }) {
        const applicator = this;
        return function (...invokeArgs) {
            const _args = [
                ...args.map(method => resolveFunction(method, this, target))
            ];
            if (applicator.post) {
                _args.push(value);
            }
            else {
                _args.unshift(value);
            }
            return execute(..._args).apply(this, invokeArgs);
        };
    }
}