@vates/compose
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -35,3 +35,3 @@ 'use strict' | ||
for (let i = 1; i < n; ++i) { | ||
value = await fns[i](value) | ||
value = await fns[i].call(this, value) | ||
} | ||
@@ -43,3 +43,3 @@ return value | ||
for (let i = 1; i < n; ++i) { | ||
value = fns[i](value) | ||
value = fns[i].call(this, value) | ||
} | ||
@@ -46,0 +46,0 @@ return value |
@@ -40,16 +40,28 @@ /* eslint-env jest */ | ||
it('first function receives this and all args', () => { | ||
expect.assertions(2) | ||
it('forwards all args to first function', () => { | ||
expect.assertions(1) | ||
const expectedArgs = [Math.random(), Math.random()] | ||
const expectedThis = {} | ||
compose( | ||
function (...args) { | ||
expect(this).toBe(expectedThis) | ||
(...args) => { | ||
expect(args).toEqual(expectedArgs) | ||
}, | ||
// add a second function to use the one function special case | ||
// add a second function to avoid the one function special case | ||
Function.prototype | ||
).apply(expectedThis, expectedArgs) | ||
)(...expectedArgs) | ||
}) | ||
it('forwards context to all functions', () => { | ||
expect.assertions(2) | ||
const expectedThis = {} | ||
compose( | ||
function () { | ||
expect(this).toBe(expectedThis) | ||
}, | ||
function () { | ||
expect(this).toBe(expectedThis) | ||
} | ||
).call(expectedThis) | ||
}) | ||
}) |
@@ -17,3 +17,3 @@ { | ||
"license": "ISC", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"engines": { | ||
@@ -20,0 +20,0 @@ "node": ">=7.6" |
@@ -14,4 +14,6 @@ ```js | ||
The first function is called with the context and all arguments of the composed function: | ||
> The call context (`this`) of the composed function is forwarded to all functions. | ||
The first function is called with all arguments of the composed function: | ||
```js | ||
@@ -18,0 +20,0 @@ const add = (x, y) => x + y |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5713
95