CJS and AMD are the primary targets for when, but instructions for a variety of setups are provided below.
As of version 3.0, when.js requires an ES5 environment. In older environments, use an ES5 shim such as poly or es5-shim
If you're already using RaveJS, just install when.js and start coding:
npm install --save whenorbower install --save whenvar when = require('when');
-
Get it.
bower install --save when, orgit clone https://github.com/cujojs/when -
Configure your loader. Here is an example of how configuring the package might look:
// using requirejs
requirejs.config({
packages: [
{ name: 'when', location: '/path/to/when', main: 'when' }
]
});
// using curl.js
curl.config({
packages: {
when: { location: '/path/to/when', main: 'when' }
}
});- Load when wherever you need it. For example, as part of a module:
define(function(require) {
var when = require('when');
// your code...
});
npm install --save whenvar when = require('when');
ringo-admin install cujojs/whenvar when = require('when');
ender add whenvar when = require('when');
git clone https://github.com/cujojs/whenvar when = require('when');orvar when = require('path/to/when');
Since when.js primarily targets modular environments, it doesn't export to the global object (window in browsers) by default. You can create your own build of when.js using browserify, if you prefer not to use an AMD or CommonJS loader in your project.
git clone https://github.com/cujojs/whennpm installnpm run browserifyto generatebuild/when.js- Or
npm run browserify-debugto build with when/monitor/console enabled <script src="path/to/when/build/when.js"></script>whenwill be available aswindow.when- Other modules will be available as sub-objects/functions, e.g.
window.when.fn.lift,window.when.sequence. See the full sub-namespace list in the browserify build file
If you would prefer to install the source via npm. Note that this will install the full when.js source, including tests, etc., into node_modules rather than the smaller, published when.js npm package.
npm install --save cujojs/whennpm install --save-dev browserify- Add
cd node_modules/when && npm run browserifyto yourpostinstallscript in your project's package.json <script src="path/to/when/build/when.js"></script>- See above for usage,
window.when, etc.
Similarly to browser global environments:
git clone https://github.com/cujojs/whennpm installnpm run browserifyto generatebuild/when.js- Or
npm run browserify-debugto build with when/monitor/console enabled importScripts('path/to/when/build/when.js');whenwill be available asself.when- Other modules will be available as sub-objects/functions, e.g.
self.when.fn.lift,self.when.sequence. See the full sub-namespace list in the browserify build file