Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 2.46 KB

README.md

File metadata and controls

76 lines (50 loc) · 2.46 KB

confine

Build Status

Solves the problem of using multiple versions of javascript libraries and executing arbitrary javascript in isolated namespaces.

Invoking confine will return an isolate. An isolate is an context where you can execute javascript code in confinement to your global namespace.

Install

bower install confine
Running Tests/Building
npm install
bower install
grunt

Usage

var isolate = confine(options, source, callbacks, error);
Confine (function)

returns an isolate object

options (object)

  • name (string) - A unique name for the isolate. If this is not specified a name will be generated.
  • path (string) - The base path for dependencies.
  • deps (object) - A key value pair where keys are the global object name and the value is the path relative to path.
  • depends (object) - A key value pair where keys are the global object (defined in deps) and the value is an array of global objects that the key depends on.
  • parameters (array) - An array of key value pairs where the key is the parameter name and value is the value of the parameter. These parameters are global to the sources you provide.

source (string) - Source code to be executed in the isolate. You can access your parameters within the source.

source (object)

  • attach (bool) - Attaches script (if function body) to isolate (see isolate's invoke method).
  • source source code to executed in the isolate.

source (array) - An array of source objects.

callbacks (array) - An array of key value pairs where keys are the function names and values are functions to be invoked within source code.

error (function) - A callback for error handling.

Isolate (object)

The following methods are accessible if you have attached your source to the isolate.

invoke(name, [arg,...]) (function) - invokes a method (called name) and passes in. arguments [arg,...]. This will return a promise with signature .then(success, error), e.g.

var isolate = confine(...,
  {
      attach: true,
      source: "return { a: function(b) { return b; } }"
  },
..);

isolate.invoke(a, [1]).then(function(value) {
    console.log(value); // 1
  });

destroy (function) - removes the isolate and container.