diff --git a/lib/aigle.js b/lib/aigle.js index eabe2885..ba224699 100644 --- a/lib/aigle.js +++ b/lib/aigle.js @@ -3765,6 +3765,17 @@ function mixin(sources, opts = {}) { if (typeof func !== 'function' || Aigle[key] && !override) { return; } + // check lodash chain + if (key === 'chain') { + const obj = func(); + if (obj && obj.__chain__) { + Aigle.chain = _resolve; + Aigle.prototype.value = function() { + return this; + }; + return; + } + } const Proxy = createProxy(func, promisify); Aigle[key] = function(value, arg1, arg2, arg3) { return new Proxy(value, arg1, arg2, arg3)._execute(); @@ -3773,4 +3784,5 @@ function mixin(sources, opts = {}) { return addProxy(this, Proxy, arg1, arg2, arg3); }; }); + return Aigle; } diff --git a/test/.eslintrc b/test/.eslintrc index 521c9fbe..e7518127 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,3 +1,5 @@ +parserOptions: + ecmaVersion: 8 rules: # Best Practices no-return-assign: "off" diff --git a/test/lib/test.mixin.js b/test/lib/test.mixin.js index 690e8a66..154622a4 100644 --- a/test/lib/test.mixin.js +++ b/test/lib/test.mixin.js @@ -13,7 +13,8 @@ parallel('mixin', () => { it('should execute with function', () => { const test1 = value => value * 2; - Aigle.mixin({ test1 }, { promisify: false }); + const obj = Aigle.mixin({ test1 }, { promisify: false }); + assert.strictEqual(obj, Aigle); return Aigle.resolve(1) .test1() .then(value => assert.strictEqual(value, 2)); @@ -40,6 +41,16 @@ parallel('mixin', () => { return promise; }); + it('should allow the lodash chain', async () => { + + const lo = Aigle.mixin(_); + const array = await lo.chain([1, 2, 3]) + .map(async n => Aigle.delay(DELAY, n * 2)) + .value(); + assert.deepEqual(array, [2, 4, 6]); + assert.strictEqual(await lo.sum(array), 12); + }); + it('should override Aigle functions', () => { Aigle.mixin({ map: _.map }, { override: true, promisify: false });