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

Worker loader #295

Merged
merged 8 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Share a module between node & browser for perspective library
  • Loading branch information
texodus committed Nov 7, 2018
commit 4b425383603e919474fb1d27e196e0e58aef292c
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ 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");
const perspective = require("@jpmorganchase/perspective");
```

### Loading data with `table()`
Expand Down
2 changes: 1 addition & 1 deletion examples/git_history/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

const {WebSocketHost} = require("@jpmorganchase/perspective/build/perspective.node.js");
const {WebSocketHost} = require("@jpmorganchase/perspective");
const exec = require("child_process").exec;

function execute(command, callback) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*
*/

const {WebSocketHost} = require("@jpmorganchase/perspective/build/perspective.node.js");
const {WebSocketHost} = require("@jpmorganchase/perspective");
new WebSocketHost({assets: [__dirname]});
2 changes: 1 addition & 1 deletion packages/perspective-viewer/src/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "@webcomponents/shadycss/custom-style-interface.min.js";
import _ from "underscore";
import {polyfill} from "mobile-drag-drop";

import perspective from "@jpmorganchase/perspective/src/js/perspective.parallel.js";
import perspective from "@jpmorganchase/perspective";
import {bindTemplate, json_attribute, array_attribute, copy_to_clipboard} from "./utils.js";
import {undrag, column_undrag, column_dragleave, column_dragover, column_drop, drop, drag_enter, allow_drop, disallow_drop} from "./dragdrop.js";

Expand Down
3 changes: 2 additions & 1 deletion packages/perspective/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@jpmorganchase/perspective",
"version": "0.2.3",
"description": "Perspective.js",
"main": "build/perspective.cjs.js",
"main": "build/perspective.node.js",
"browser": "build/perspective.cjs.js",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective/src/config/perspective.cjs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require("./common.config.js");

module.exports = Object.assign({}, common(), {
entry: "./src/js/perspective.parallel.js",
externals: [/^[a-z0-9\@].*$/],
externals: [/node_modules\/\@(?!apache-arrow)/, /perspective.node.js/],
output: {
filename: "perspective.cjs.js",
library: "perspective",
Expand Down
30 changes: 11 additions & 19 deletions packages/perspective/src/js/perspective.parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import {ScriptPath} from "./utils.js";

import {TYPE_AGGREGATES, AGGREGATE_DEFAULTS, TYPE_FILTERS, FILTER_DEFAULTS, SORT_ORDERS} from "./defaults.js";
import * as defaults from "./defaults.js";

import {worker} from "./api.js";

Expand Down Expand Up @@ -175,22 +175,14 @@ class WebSocketWorker extends worker {
}
}

export default {
worker: function(url) {
if (url) {
return new WebSocketWorker(url);
} else {
return new WebWorker();
}
},

TYPE_AGGREGATES: TYPE_AGGREGATES,

TYPE_FILTERS: TYPE_FILTERS,

AGGREGATE_DEFAULTS: AGGREGATE_DEFAULTS,

FILTER_DEFAULTS: FILTER_DEFAULTS,

SORT_ORDERS: SORT_ORDERS
exports.worker = function(url) {
if (url) {
return new WebSocketWorker(url);
} else {
return new WebWorker();
}
};

for (let prop of Object.keys(defaults)) {
exports[prop] = defaults[prop];
}
61 changes: 61 additions & 0 deletions packages/perspective/src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,67 @@ export function bindall(self) {
}
}

/**
* Detect Node.js.
*
* Returns
* -------
* True if the current script is running in Node.js.
*/
export function detectNode() {
return typeof window === "undefined";
}

/**
* Detect Internet Explorer.
*
* Returns
* -------
* True if the current script is running in Internet Explorer.
*/
export function detectIE() {
if (typeof window === "undefined") return false;
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0) {
return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)), 10);
}
var trident = ua.indexOf("Trident/");
if (trident > 0) {
var rv = ua.indexOf("rv:");
return parseInt(ua.substring(rv + 3, ua.indexOf(".", rv)), 10);
}
var edge = ua.indexOf("Edge/");
if (edge > 0) {
return parseInt(ua.substring(edge + 5, ua.indexOf(".", edge)), 10);
}
return false;
}

/**
* Detect Chrome.
*
* Returns
* -------
* Detect if the current script is running in Chrome.
*/
export function detectChrome() {
var isChromium = window.chrome,
winNav = window.navigator,
vendorName = winNav.vendor,
isOpera = winNav.userAgent.indexOf("OPR") > -1,
isIEedge = winNav.userAgent.indexOf("Edge") > -1,
isIOSChrome = winNav.userAgent.match("CriOS");

if (isIOSChrome) {
return true;
} else if (isChromium !== null && typeof isChromium !== "undefined" && vendorName === "Google Inc." && isOpera === false && isIEedge === false) {
return true;
} else {
return false;
}
}

/**
* An Object for capturing details of the invoking script's origin.
*
Expand Down