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

breeze

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

breeze - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

4

breeze.js

@@ -49,4 +49,6 @@ var isPromise = require('is-promise')

if (isPromise(err)) {
var args = Array.prototype.slice.call(arguments, 1)
var success = function () {
var args = Array.prototype.slice.call(arguments, 0)
var successArgs = Array.prototype.slice.call(arguments, 0)
args = args.concat(successArgs)
args.unshift(null)

@@ -53,0 +55,0 @@ handler.apply(context, args)

@@ -44,8 +44,9 @@ var breeze = require('../breeze')

var flow = breeze(function (next) {
next(SuccessPromise)
next(SuccessPromise, ';^)')
})
// When promise is successful
flow.then(function (next, value) {
console.log('Promise should pass with ":)":', value)
flow.then(function (next, passedValue, promiseValue) {
console.log('Passed values should come first ";^)":', passedValue)
console.log('Promise should pass with ":)":', promiseValue)
})

@@ -52,0 +53,0 @@

{
"name": "breeze",
"version": "1.1.3",
"version": "1.1.4",
"description": "Functional async flow control library",

@@ -5,0 +5,0 @@ "main": "breeze.js",

# Breeze
Functional async flow control library.
Functional async flow control library. Turn your asynchronous code into bite-sized synchronous looking functions.

@@ -26,5 +26,5 @@ [![version][npm-version]][npm-url]

- `breeze(next)` - Initialize breeze flow system, supports initial `.then` method.
- `.when(arg, next)` - When `arg` is truthy, add `next` to the stack
- `.maybe(arg, next)` - When `arg` is truthy, add `next` to the stack, sugar for `breeze.when`
- `.some(arg, next)` - When `arg` is truthy and no other `some` or `none` has ran, add to the stack
- `.when(check, next)` - When `check` is truthy, add `next` to the stack
- `.maybe(check, next)` - When `check` is truthy, add `next` to the stack, sugar for `breeze.when`
- `.some(check, next)` - When `check` is truthy and no other `some` or `none` has ran, add to the stack
- `.none(next)` - Whenever no `some` have ran, add callback to the stack

@@ -35,5 +35,49 @@ - `.then(next)` - Add callback to stack

### Next
The `next` method passed through breeze has a very small api. It accepts two variants of usage, normal node style
`err, arguments...`, and `promise, arguments...`.
When a *truthy* `err` is passed the system will halt (no other actions will be taken) and `.catch` will be triggered.
When a `promise` is passed the system will attach to either the `then / catch` methods, or the `.then(then, catch)`
method style depending on the promise type passed. Whenever the `then` is invoked, any `arguments` passed along with
the passed promise are placed at the *front* of the arguments array, and the success arguments will be *last*.
This allows you to chain multiple promises while still passing values down the chain.
## Example
```js
// Initialize breeze, fetch a user
var flow = breeze(function (next) {
next(api(token).getUser('nijikokun'))
})
// Fetch user todos, pass user along the chain
flow.then(function (next, user) {
next(user.getTodos(), user)
})
// Catch bugs before you do your work!
flow.when(function (user, todos) {
return todos.getLength() < 0
}, function (next, user, todos) {
todos.reset()
next(todos.save(), user)
})
// Do whatever else you want
flow.then(function (next, user, todos) {
// store user and todos.
})
flow.catch(function (err) {
// show error in application
})
```
## Examples
Check out the [examples](examples/) directory for in-depth examples of how to use breeze.
Check out the [examples](examples/) directory for in-depth examples and tutorials of how to use breeze.

@@ -40,0 +84,0 @@ ## License

@@ -206,2 +206,26 @@ var assert = require('assert')

})
it('should properly handle directly passed values w/ promise', function (done) {
var fixture = 'hello world'
var noop = function () {}
var promise = {
then: function (next) {
next(fixture)
return {
catch: noop
}
},
catch: noop
}
breeze(function (next) {
next(promise, 'testing')
}).then(function (next, passedValue, promiseValue) {
assert(passedValue === 'testing')
assert(promiseValue === fixture)
done()
}).catch(function (err) {
assert(false)
})
})
})
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