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

Refactor __WORKER__ into proper singleton #292

Merged
merged 1 commit into from
Nov 7, 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
39 changes: 13 additions & 26 deletions docs/perspective-viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ names.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('sort', JSON.stringify([["x","desc"]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer sort='[["x","desc"]]'></perspective-viewer>
Expand All @@ -79,16 +77,14 @@ The set of visible columns.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('columns', JSON.stringify(["x", "y'"]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer columns='["x", "y"]'></perspective-viewer>
Expand All @@ -104,16 +100,14 @@ The set of visible columns.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('computed-columns', JSON.stringify([{name: "x+y", func: "add", inputs: ["x", "y"]}]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer computed-columns="[{name:'x+y',func:'add',inputs:['x','y']}]""></perspective-viewer>
Expand All @@ -133,16 +127,14 @@ The set of column aggregate configurations.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('aggregates', JSON.stringify({x: "distinct count"}));
```

via HTML

_via HTML_

```javascript
<perspective-viewer aggregates='{"x": "distinct count"}'></perspective-viewer>
Expand All @@ -154,8 +146,7 @@ The set of column filter configurations.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let filters = [
Expand All @@ -166,8 +157,7 @@ let elem = document.getElementById('my_viewer');
elem.setAttribute('filters', JSON.stringify(filters));
```

via HTML

_via HTML_

```javascript
<perspective-viewer filters='[["x", "<", 3], ["y", "contains", "abc"]]'></perspective-viewer>
Expand Down Expand Up @@ -239,8 +229,7 @@ element, its internal `perspective.table` will also be deleted.

**Examples**

Load JSON

_Load JSON_

```javascript
const my_viewer = document.getElementById('#my_viewer');
Expand All @@ -250,16 +239,14 @@ my_viewer.load([
]);
```

Load CSV

_Load CSV_

```javascript
const my_viewer = document.getElementById('#my_viewer');
my_viewer.load("x,y\n1,a\n2,b");
```

Load perspective.table

_Load perspective.table_

```javascript
const my_viewer = document.getElementById('#my_viewer');
Expand Down
39 changes: 13 additions & 26 deletions packages/perspective-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ names.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('sort', JSON.stringify([["x","desc"]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer sort='[["x","desc"]]'></perspective-viewer>
Expand All @@ -79,16 +77,14 @@ The set of visible columns.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('columns', JSON.stringify(["x", "y'"]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer columns='["x", "y"]'></perspective-viewer>
Expand All @@ -104,16 +100,14 @@ The set of visible columns.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('computed-columns', JSON.stringify([{name: "x+y", func: "add", inputs: ["x", "y"]}]));
```

via HTML

_via HTML_

```javascript
<perspective-viewer computed-columns="[{name:'x+y',func:'add',inputs:['x','y']}]""></perspective-viewer>
Expand All @@ -133,16 +127,14 @@ The set of column aggregate configurations.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let elem = document.getElementById('my_viewer');
elem.setAttribute('aggregates', JSON.stringify({x: "distinct count"}));
```

via HTML

_via HTML_

```javascript
<perspective-viewer aggregates='{"x": "distinct count"}'></perspective-viewer>
Expand All @@ -154,8 +146,7 @@ The set of column filter configurations.

**Examples**

via Javascript DOM

_via Javascript DOM_

```javascript
let filters = [
Expand All @@ -166,8 +157,7 @@ let elem = document.getElementById('my_viewer');
elem.setAttribute('filters', JSON.stringify(filters));
```

via HTML

_via HTML_

```javascript
<perspective-viewer filters='[["x", "<", 3], ["y", "contains", "abc"]]'></perspective-viewer>
Expand Down Expand Up @@ -239,8 +229,7 @@ element, its internal `perspective.table` will also be deleted.

**Examples**

Load JSON

_Load JSON_

```javascript
const my_viewer = document.getElementById('#my_viewer');
Expand All @@ -250,16 +239,14 @@ my_viewer.load([
]);
```

Load CSV

_Load CSV_

```javascript
const my_viewer = document.getElementById('#my_viewer');
my_viewer.load("x,y\n1,a\n2,b");
```

Load perspective.table

_Load perspective.table_

```javascript
const my_viewer = document.getElementById('#my_viewer');
Expand Down
25 changes: 14 additions & 11 deletions packages/perspective-viewer/src/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,20 @@ function sort_order_clicked() {
*
*/

let __WORKER__;

function get_worker() {
if (__WORKER__ === undefined) {
__WORKER__ = perspective.worker();
}
return __WORKER__;
}
let worker = (function() {
let __WORKER__;
return {
getInstance: function() {
if (__WORKER__ === undefined) {
__WORKER__ = perspective.worker();
}
return __WORKER__;
}
};
})();

if (document.currentScript && document.currentScript.hasAttribute("preload")) {
get_worker();
worker.getInstance();
}

function get_aggregate_attribute() {
Expand Down Expand Up @@ -1312,7 +1315,7 @@ class View extends ViewPrivate {
if (this._table) {
return this._table._worker;
}
return get_worker();
return worker.getInstance();
}

/**
Expand Down Expand Up @@ -1356,7 +1359,7 @@ class View extends ViewPrivate {
if (data.hasOwnProperty("_name")) {
table = data;
} else {
table = get_worker().table(data, options);
table = worker.getInstance().table(data, options);
table._owner_viewer = this;
}
let _promises = [loadTable.call(this, table)];
Expand Down