From aa4f3bb38e70f3e2a046bc932a3854e95457e763 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Tue, 17 Aug 2021 12:21:31 +0200 Subject: [PATCH] #33 --- packages/monster/source/data/pipe.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/monster/source/data/pipe.js b/packages/monster/source/data/pipe.js index 84d1f0f82..57d34cc27 100644 --- a/packages/monster/source/data/pipe.js +++ b/packages/monster/source/data/pipe.js @@ -40,7 +40,7 @@ const DELIMITER = '|'; * * @example * import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.9.0/dist/modules/data/pipe.js'; - * + * * let obj = { * a: { * b: { @@ -50,7 +50,7 @@ const DELIMITER = '|'; * } * } * } - * + * * console.log(new Pipe('path:a.b.c.d | toupper | prefix:Hello\\ ').run(obj)); * // ↦ Hello WORLD * @@ -63,7 +63,7 @@ class Pipe extends Base { /** * * @param {string} pipe a pipe consists of commands whose input and output are connected with the pipe symbol `|`. - * @throws {TypeError} + * @throws {TypeError} */ constructor(pipe) { super(); @@ -71,7 +71,7 @@ class Pipe extends Base { this.pipe = pipe.split(DELIMITER).map((v) => { return new Transformer(v); }); - + } @@ -79,23 +79,18 @@ class Pipe extends Base { * * @param {string} name * @param {function} callback + * @param {object} context * @returns {Transformer} * @throws {TypeError} value is not a string * @throws {TypeError} value is not a function */ - setCallback(name, callback) { + setCallback(name, callback, context) { - for(const [,t] of Object.entries(this.pipe)) { - t.setCallback(name, callback); + for (const [, t] of Object.entries(this.pipe)) { + t.setCallback(name, callback, context); } - + return this; - - // return this.pipe.reduce((accumulator, transformer, currentIndex, array) => { - // return transformer.setCallback(name,callback); - // }, value); - - } /** -- GitLab