Home Reference Source Test Repository

buildDocs/applicators/ComposeApplicator.js

  1. import { identity } from 'lodash';
  2. import { Applicator } from './Applicator';
  3. import { resolveFunction } from '../utils';
  4. export class ComposeApplicator extends Applicator {
  5. constructor(_config = {}) {
  6. super();
  7. this._config = _config;
  8. }
  9. get post() {
  10. return this._config.post === true;
  11. }
  12. apply({ config: { execute }, value = identity, args, target }) {
  13. const applicator = this;
  14. return function (...invokeArgs) {
  15. const _args = [
  16. ...args.map(method => resolveFunction(method, this, target))
  17. ];
  18. if (applicator.post) {
  19. _args.push(value);
  20. }
  21. else {
  22. _args.unshift(value);
  23. }
  24. return execute(..._args).apply(this, invokeArgs);
  25. };
  26. }
  27. }