Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better documentation for worker() method usage in node.js & the bro… #245

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ title: Usage

As a library, `perspective` provides a suite of streaming pivot, aggregate, filter
and sort operations for tabular data. The engine can be instantiated in process,
or in a Web Worker (browser only).
or in a Web Worker (browser only), and is published in the `@jpmorganchase/perspective`
NPM module.

### In the browser

Via ES6 module and/or Babel:
The `main` entry point for the `@jpmorganchase/perspective` runs in a Web
Worker, such that the CPU workload is segregated from the web application in
which it is embedded, and so the bulk of engine code can be lazy-loaded only
after browser feature detection determines whether WebAssembly is supported.

The library can be imported ia ES6 module and/or Babel:

```javascript
import perspective from 'perspective';
Expand All @@ -26,7 +32,7 @@ const perspective = require('perspective');
```

Perspective can also be referenced via the global `perspective` module name in vanilla
Javascript.
Javascript, when e.g. importing `@jpmorganchase/perspective` [via a CDN](https://unpkg.com/@jpmorganchase/[email protected]/build/perspective.js).

Once imported, you'll need to instance a `perspective` engine via the `worker()`
method. This will create a new WebWorker (browser) or Process (node.js), and
Expand All @@ -37,8 +43,18 @@ and data accumulation will occur in this separate process.
const worker = perspective.worker();
```

The `worker` symbol will expose the full `perspective` API for one managed
Web Worker process. You are free to create as many as your browser supports,
but be sure to keep track of the `worker` instances themselves, as you'll
need them to interact with your data in each instance.

### In Node.js

The `Node.js` runtime for the `@jpmorganchase/perpsective` module runs
in-process by defualt, and does not implement a `child_process` interface.
Hence, there is no `worker()` method, and the module object itself directly
exports the full `perspective` API.

```javascript
const perspective = require('@jpmorganchase/perspective/build/perspective.node.js');
```
Expand Down
1 change: 1 addition & 0 deletions packages/perspective/src/js/perspective.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let Module = load_perspective({
});

module.exports = perspective(Module);
delete module.exports["worker"];

let CLIENT_ID_GEN = 0;

Expand Down