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.4 to 1.1.5

45

breeze.js

@@ -33,6 +33,7 @@ var isPromise = require('is-promise')

if (err) {
if (!system.onError) {
if (!system.onError || !system.onDeferredError) {
system.err = err
} else {
system.onError(err)
if (system.onError) system.onError(err)
if (system.onDeferredError) system.onDeferredError(err)
}

@@ -74,2 +75,3 @@

Breeze.prototype.run = function _breezeRun () {
var system = this
var args = this.args || []

@@ -100,3 +102,3 @@ var context = this.context || this

if ((typeof func[1] === 'function' && func[1].apply(this.context, args)) || func[1]) {
if ((typeof func[1] === 'function' && func[1].apply(this.context, args)) || (typeof func[1] !== 'function' && func[1])) {
switch (func[0]) {

@@ -217,2 +219,7 @@ case 'when': this.hasWhenHappened = true; break;

next(this.err)
if (this.onDeferredError) {
this.onDeferredError(this.err)
}
return this

@@ -227,2 +234,34 @@ }

/**
* Generates a deferred promise
*
* @return {Function}
*/
Breeze.prototype.promise = function _breezeDeferred () {
var system = this
var deferred = {
then: function (next) {
if (system.err) return deferred
system.steps.push(function () {
return next.apply(this, Array.prototype.slice.call(arguments, 1))
})
system.check()
return deferred
},
catch: function (next) {
if (system.err) {
return next(system.err)
}
system.onDeferredError = next
return deferred
}
}
return deferred
}
/**
* Resets system

@@ -229,0 +268,0 @@ */

2

package.json
{
"name": "breeze",
"version": "1.1.4",
"version": "1.1.5",
"description": "Functional async flow control library",

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

@@ -32,2 +32,3 @@ # Breeze

- `.catch(next)` - Any error caught will terminate stack and be sent here
- `.promise()` - Returns a deferred promise system, allowing for a second `.catch`
- `.reset()` - Reset current system

@@ -51,27 +52,46 @@

```js
// Initialize breeze, fetch a user
var flow = breeze(function (next) {
next(api(token).getUser('nijikokun'))
})
function fetchUserTodos (username) {
// Initialize breeze, fetch a user
var flow = breeze(function (next) {
next(api(token).getUser(username))
})
// Fetch user todos, pass user along the chain
flow.then(function (next, user) {
next(user.getTodos(), user)
})
// 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)
})
// 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.
// Do whatever else you want
flow.then(function (next, user, todos) {
next(null, user, todos)
})
flow.catch(function (err) {
// handle internal function error should you want
if (err.code === 500) {
console.error('Holy Switch A Roo Batman! I think something really went wrong.')
}
console.error(err)
})
return flow.promise()
}
var promise = fetchUserTodos('nijikokun')
promise.then(function (user, todos) {
// Show todos
})
flow.catch(function (err) {
// show error in application
promise.catch(function (err) {
// Show error in application
})

@@ -78,0 +98,0 @@ ```

@@ -54,3 +54,5 @@ var assert = require('assert')

})
.maybe(route === 'B', function (next) {
.maybe(function () {
route === 'B'
}, function (next) {
return next(null, fixtureB)

@@ -231,2 +233,19 @@ })

})
it('should properly success through returned promise', function (done) {
var fixture = 'hello world'
var flow = breeze(function (next) {
next(null, 'testing')
})
var promise = flow.promise()
promise.then(function (value) {
assert(value === 'testing')
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