bottender-compose
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -0,1 +1,23 @@ | ||
# 0.6.0 / 2018-03-21 | ||
* [new] Support passing function as argument to context methods: | ||
You can pass function as argument to handle time-specified or context-specified case, for example: | ||
```js | ||
// Lazy execution | ||
B.sendText(() => `Now: ${new Date()}`); | ||
// Use user information on context | ||
B.sendText( | ||
context => | ||
`${context.session.user.first_name} ${ | ||
context.session.user.last_name | ||
}, You are the lucky one.` | ||
); | ||
// Use event information | ||
B.sendText(context => `Received: ${context.event.text}`); | ||
``` | ||
# 0.5.1 / 2017-12-20 | ||
@@ -2,0 +24,0 @@ |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"main": "src/index", | ||
@@ -12,0 +12,0 @@ "scripts": { |
@@ -201,3 +201,3 @@ # bottender-compose | ||
### Other Methods | ||
### Context Methods | ||
@@ -266,3 +266,2 @@ #### Common | ||
* `replyImageCarouselTemplate` | ||
* `sendImageCarouselTemplate` | ||
* `push` | ||
@@ -327,4 +326,24 @@ * `pushText` | ||
## Passing Function as Argument to Context Method | ||
You can pass function as argument to handle time-specified or context-specified case, for example: | ||
```js | ||
// Lazy execution | ||
B.sendText(() => `Now: ${new Date()}`); | ||
// Use user information on context | ||
B.sendText( | ||
context => | ||
`${context.session.user.first_name} ${ | ||
context.session.user.last_name | ||
}, You are the lucky one.` | ||
); | ||
// Use event information | ||
B.sendText(context => `Received: ${context.event.text}`); | ||
``` | ||
## License | ||
MIT © [Yoctol](https://github.com/Yoctol/bottender-compose) |
@@ -13,1 +13,15 @@ const { sendText } = require('../'); | ||
}); | ||
it('should call parameter as function', async () => { | ||
const mockFn = jest.fn(); | ||
mockFn.mockReturnValue('haha'); | ||
const action = sendText(mockFn); | ||
const context = { | ||
sendText: jest.fn(() => Promise.resolve()), | ||
}; | ||
await action(context); | ||
expect(context.sendText).toBeCalledWith('haha'); | ||
expect(mockFn).toBeCalled(); | ||
}); |
@@ -21,3 +21,11 @@ const { | ||
if (!exports[method]) { | ||
exports[method] = (...args) => context => context[method](...args); | ||
exports[method] = (...args) => context => | ||
context[method]( | ||
...args.map(arg => { | ||
if (typeof arg === 'function') { | ||
return arg(context); | ||
} | ||
return arg; | ||
}) | ||
); | ||
} | ||
@@ -24,0 +32,0 @@ }); |
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
642
347
29748
32