Skip to content

Latest commit

 

History

History
80 lines (57 loc) · 2.85 KB

installation.md

File metadata and controls

80 lines (57 loc) · 2.85 KB

Getting Started

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

AMD

  1. Get it. bower install --save when, or git clone https://github.com/cujojs/when

  2. 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' }
  }
});
  1. Load when wherever you need it. For example, as part of a module:
define(function(require) {
	var when = require('when');
});

Node

  1. npm install --save when
  2. var when = require('when');

RingoJS

  1. ringo-admin install cujojs/when
  2. var when = require('when');

Ender

  1. ender add when
  2. var when = require('when');

Other CommonJS environments (eg vert.x 1.x and 2.x with CommonJS module support)

  1. git clone https://github.com/cujojs/when
  2. var when = require('when'); or var when = require('path/to/when');

Browser environments (via browserify)

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.

  1. git clone https://github.com/cujojs/when
  2. npm install
  3. npm run browserify to generate build/when.js
  4. Or npm run browserify-debug to build with when/monitor/console enabled
  5. <script src="path/to/when/build/when.js"></script>
  6. when will be available as window.when
  7. 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

Web Worker (via browserify)

Similarly to browser global environments:

  1. git clone https://github.com/cujojs/when
  2. npm install
  3. npm run browserify to generate build/when.js
  4. Or npm run browserify-debug to build with when/monitor/console enabled
  5. importScripts('path/to/when/build/when.js');
  6. when will be available as self.when
  7. 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