Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rahatarmanahmed/choo-promise
A choo plugin that lets you use promises for effects and subscriptions
https://github.com/rahatarmanahmed/choo-promise
Last synced: 1 day ago
JSON representation
A choo plugin that lets you use promises for effects and subscriptions
- Host: GitHub
- URL: https://github.com/rahatarmanahmed/choo-promise
- Owner: rahatarmanahmed
- License: other
- Created: 2017-02-04T20:56:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-02T10:48:42.000Z (over 7 years ago)
- Last Synced: 2024-04-26T09:20:21.596Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-choo - choo-promise - Use promises in effects and subscriptions. (Uncategorized / Uncategorized)
README
# choo-promise [![Build Status](https://travis-ci.org/rahatarmanahmed/choo-promise.svg?branch=master)](https://travis-ci.org/rahatarmanahmed/choo-promise)
A plugin for [choo](https://github.com/yoshuawuyts/choo) (or [barracks](https://github.com/yoshuawuyts/barracks)) that allows you to return promises to end effects and subscriptions. The send function passed to effects and subscriptions is also promisified.## Installing
`npm install choo-promise`## Example usage
```js
var choo = require('choo')
var chooPromise = require('choo-promise')
var Bluebird = require('bluebird')var app = choo()
// You can optionally provide your own promise implementation
app.use(chooPromise({ Promise: Bluebird }))app.model({
state: { value: null }
effects: {
updateValue: async (state, data, send) => {
var value = await fetchSomeData(data)
return send('setValue', { value })
}
},
subscriptions: {
initValue: (send) => {
var value = await fetchSomeData(data)
return send('setValue', { value })
}
}
})
```### Isn't there another package that does this?
Yup! There's [`barracks-promisify-plugin`](https://github.com/myobie/barracks-promisify-plugin), which does pretty much exactly the same thing. The only differences (at the time of writing) are:
- `barracks-promisify-plugin` uses ES6 features, which you may or may not care about (some tools don't yet support ES6 syntax without pre-transpiling, like uglify). `choo-promise` doesn't use ES6 features.
- `choo-promise` gives you the option to provide your own Promise implementation (like Bluebird) if you want. It will default to the native Promise.