2.0.0 • Published 8 years ago

rho-cc-node-style-callback v2.0.0

Weekly downloads
2
License
MPL-2.0
Repository
github
Last release
8 years ago

rho-cc-node-style-callback

Create rho-contracts for Node-style callbacks.

Usage

You must use the Body Labs package, rho-contracts-fork:

  "dependencies": {
    "rho-contracts-fork": "^1.3.0"
  }

Use this module to create contracts for a Node-style callbacks. The returned contracts accept functions whose first argument satisfies some error contract, and the other arguments are specified the same way as c.fun.

In the Node-style callback convention, any non-null non-undefined value for the first argument indicates an error. When an error is indicated, the other arguments must not be present, else a contract error is raised.

As a special case, invoking a callback with no arguments will invoke the wrapped function with one argument set to undefined.

Calling withError on the returned contract changes the type of the error argument to the contract specified.

The main entry point of this module is withDefaultError, which sets the expected error contract, like this:

var c = require('rho-contracts-fork');

var cc = {};

cc.callback = require('rho-cc-node-style-callback').withDefaultError(c.error)
cc.countCallback = cc.callback({ result: c.number })

Installation

npm install rho-contracts-fork rho-cc-node-style-callback

Contribute

Pull requests welcome!

Support

If you are having issues, please let us know.

License

The project is licensed under the Mozilla Public License Version 2.0.

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago