Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bottender-compose

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bottender-compose - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

22

CHANGELOG.md

@@ -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 @@

2

package.json

@@ -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 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc