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

Fix react and remote-workspace examples #1411

Merged
merged 3 commits into from
May 6, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ docs/static/css/material.dark.css
docs/i18n/en.json
docs/static/js

rust/perspective-vieux/target.vscode
8 changes: 2 additions & 6 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.8.0",
"description": "An example app built using `@finos/perspective-viewer`.",
"scripts": {
"start": "webpack-dev-server --open",
"start": "webpack serve --open",
"webpack": "webpack --colour"
},
"keywords": [],
Expand All @@ -21,12 +21,8 @@
"@finos/perspective-webpack-plugin": "^0.8.0",
"@types/react": "^16.8.6",
"@types/react-dom": "^16.9.4",
"css-loader": "^0.28.7",
"html-webpack-plugin": "^3.2.0",
"source-map-loader": "^0.2.4",
"style-loader": "^0.18.2",
"ts-loader": "^6.2.1",
"typescript": "^3.7.4",
"webpack-dev-server": "^3.11.2"
"typescript": "^3.7.4"
}
}
2 changes: 1 addition & 1 deletion examples/react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: ["ts-loader"]
loader: "ts-loader"
},
{
test: /\.css$/,
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.8.0",
"description": "An example app built using `@finos/perspective-workspace`.",
"scripts": {
"start:server": "webpack-dev-server --open",
"start:server": "webpack serve --open",
"start:client": "node server.js",
"start": "npm-run-all -p start:server start:client"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-workspace/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const perspective = require("@finos/perspective");
const {securities} = require("../datasources");

const host = new perspective.WebSocketServer();
const host = new perspective.WebSocketServer({port: 8081});
securities().then(table => host.host_table("securities_table", table));
8 changes: 8 additions & 0 deletions examples/remote-workspace/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
</body>
</html>
8 changes: 4 additions & 4 deletions examples/remote-workspace/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import "@finos/perspective-workspace";

import "./index.less";

window.addEventListener("load", async () => {
const websocket = perspective.websocket("ws://localhost:8080");
window.addEventListener("DOMContentLoaded", async () => {
const websocket = perspective.websocket("ws://localhost:8081");
const worker = perspective.shared_worker();
const view = websocket.open_view("securities");
const table = await worker.table(view, {limit: 10000});
const server_table = websocket.open_table("securities_table");
const table = await worker.table(await server_table.view(), {limit: 10000});

const workspace = document.createElement("perspective-workspace");
document.body.appendChild(workspace);
Expand Down
7 changes: 6 additions & 1 deletion examples/remote-workspace/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

const PerspectivePlugin = require("@finos/perspective-webpack-plugin");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require("path");

module.exports = {
mode: process.env.NODE_ENV || "development",
Expand All @@ -18,7 +19,8 @@ module.exports = {
},
plugins: [
new HtmlWebPackPlugin({
title: "Workspace Example"
title: "Workspace Example",
template: "./src/index.html"
}),
new PerspectivePlugin({})
],
Expand All @@ -30,5 +32,8 @@ module.exports = {
}
]
},
devServer: {
contentBase: [path.join(__dirname, "dist"), path.join(__dirname, "../../node_modules/superstore-arrow")]
},
devtool: "source-map"
};
5 changes: 5 additions & 0 deletions examples/workspace/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module.exports = {
],
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"]
},
{
test: /\.less$/,
use: [{loader: "style-loader"}, {loader: "css-loader"}, {loader: "less-loader"}]
Expand Down
20 changes: 13 additions & 7 deletions packages/perspective-viewer/src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ export const invertPromise = () => {
return promise;
};

export function throttlePromise(target, property, descriptor) {
export function throttlePromise(target, property, descriptor, clear = false) {
if (typeof target === "boolean") {
return function(target, property, descriptor) {
return throttlePromise(target, property, descriptor, true);
};
}

// Each call to `throttlePromise` has a unique `lock`
const lock = Symbol("private lock");
const _super = descriptor.value;
Expand Down Expand Up @@ -247,7 +253,7 @@ export function throttlePromise(target, property, descriptor) {
// If this invocation is still the latest, clear the attribute
// state.
// TODO this is likely not he behavior we want for this event ..
if (id === this[lock].gen) {
if (id === this[lock].gen && clear) {
this.removeAttribute("updating");
this.dispatchEvent(new Event("perspective-update-complete"));
}
Expand All @@ -260,12 +266,12 @@ export function throttlePromise(target, property, descriptor) {

// A function which clears the lock just like the main wrapper, but then
// does nothing.
descriptor.value.flush = async function() {
if (this[lock]?.lock) {
await this[lock].lock;
descriptor.value.flush = async function(obj) {
if (obj[lock]?.lock) {
await obj[lock].lock;
await new Promise(requestAnimationFrame);
if (this[lock]?.lock) {
await this[lock].lock;
if (obj[lock]?.lock) {
await obj[lock].lock;
}
}
};
Expand Down
11 changes: 8 additions & 3 deletions packages/perspective-viewer/src/js/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ class PerspectiveViewer extends ActionElement {
*/
async load(data) {
let table;
const resolve = this._set_updating();

if (data instanceof Promise) {
this._vieux.load(data);
table = await data;
Expand All @@ -585,13 +587,15 @@ class PerspectiveViewer extends ActionElement {
this._vieux.load(Promise.resolve(data));
table = data;
} else {
resolve();
throw new Error(`Unrecognized input type ${typeof data}. Please use a \`perspective.Table()\``);
}
}
if (this.isConnected) {
await this._load_table(table);
await this._load_table(table, resolve);
} else {
this._table = table;
this._table_resolve = resolve;
}
}

Expand All @@ -615,7 +619,8 @@ class PerspectiveViewer extends ActionElement {
* @param {any} widget A `<perspective-viewer>` instance to clone.
*/
clone(widget) {
this._load_table(widget.table);
const resolve = this._set_updating();
this._load_table(widget.table, resolve);
this.restore(widget.save());
}

Expand Down Expand Up @@ -716,7 +721,7 @@ class PerspectiveViewer extends ActionElement {
* attribute state has been applied.
*/
async flush() {
await Promise.all([this._updating_promise || Promise.resolve(), this.notifyResize.flush()]);
await Promise.all([this._updating_promise || Promise.resolve(), this.notifyResize.flush(this)]);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions packages/perspective-viewer/src/js/viewer/perspective_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ export class PerspectiveElement extends StateElement {
* @param {*} table
* @param {*} computed
*/
async _load_table(table) {
async _load_table(table, resolve) {
this.shadowRoot.querySelector("#app").classList.add("hide_message");
const resolve = this._set_updating();

this._clear_state();
this._table = table;
Expand Down Expand Up @@ -536,10 +535,12 @@ export class PerspectiveElement extends StateElement {
}

_check_loaded_table() {
if (this._table) {
if (this._table && this._table_resolver) {
const table = this._table;
const resolve = this._table_resolver;
delete this._table;
this._load_table(table);
delete this._table_resolver;
this._load_table(table, resolve);
}
}

Expand Down Expand Up @@ -584,7 +585,7 @@ export class PerspectiveElement extends StateElement {
return resolve;
}

@throttlePromise
@throttlePromise(true)
async _update(ignore_size_check, force_update, limit_points) {
await new Promise(setTimeout);
await this._new_view({ignore_size_check, force_update, limit_points});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

perspective-column-style {
background-color: @grey700;
color: @grey60;
color: #FFFFFF;
border: 1px solid @grey500;
--input--border-color: @grey500;
--active-color: #2770a9;
--inactive-color: @grey500;
}

perspective-viewer, .perspective-viewer-material-dense-dark{
Expand Down
1 change: 1 addition & 0 deletions packages/perspective-viewer/src/themes/material-dense.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ perspective-column-style {
color: #161616;
border: 1px solid #E0E4E9;
--input--border-color: #E0E4E9;
--active-color: @blue500;
}

perspective-viewer, .perspective-viewer-material-dense {
Expand Down
4 changes: 3 additions & 1 deletion packages/perspective-viewer/src/themes/material.dark.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

perspective-column-style {
background-color: @grey700;
color: @grey60;
color: #FFFFFF;
border: 1px solid @grey500;
--input--border-color: @grey500;
--active-color: #2770a9;
--inactive-color: @grey500;
}

perspective-viewer, .perspective-viewer-material-dark {
Expand Down
1 change: 1 addition & 0 deletions packages/perspective-viewer/src/themes/material.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ perspective-column-style {
color: #161616;
border: 1px solid #E0E4E9;
--input--border-color: #E0E4E9;
--active-color: @blue500;
}

.perspective-viewer-material-base() {
Expand Down
14 changes: 0 additions & 14 deletions packages/perspective-workspace/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ class PerspectiveWorkspaceElement extends HTMLElement {
*/
restore(layout) {
this.workspace.restore(layout);
MessageLoop.flush();
}

/**
* An async function which resolves when all pending DOM changes at the
* time of invocation are resolved.
*/
async flush() {
MessageLoop.flush();
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
await Promise.all(Array.from(this.children).map(x => x.flush()));
}

addTable(name, table) {
Expand Down Expand Up @@ -186,7 +174,6 @@ class PerspectiveWorkspaceElement extends HTMLElement {
*/
notifyResize() {
this.workspace.update();
MessageLoop.flush();
}

_light_dom_changed() {
Expand Down Expand Up @@ -223,7 +210,6 @@ class PerspectiveWorkspaceElement extends HTMLElement {
MessageLoop.sendMessage(this.workspace, Widget.Msg.BeforeAttach);
container.insertBefore(this.workspace.node, null);
MessageLoop.sendMessage(this.workspace, Widget.Msg.AfterAttach);
MessageLoop.flush();

window.onresize = this.workspace.update.bind(this.workspace);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/perspective-workspace/src/theme/material.dark.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ perspective-viewer.workspace-master-widget {

perspective-column-style {
background-color: @grey700;
color: @grey60;
color: #FFFFFF;
border: 1px solid @grey500;
--input--border-color: @grey500;
--active-color: #2770a9;
--inactive-color: @grey500;
}

.p-Menu {
Expand Down
1 change: 1 addition & 0 deletions packages/perspective-workspace/src/theme/material.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ perspective-column-style {
color: #161616;
border: 1px solid #E0E4E9;
--input--border-color: #E0E4E9;
--active-color: @blue500;
}

.perspective-workspace-material-base() {
Expand Down
12 changes: 6 additions & 6 deletions packages/perspective-workspace/test/js/integration/dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ utils.with_server({paths: PATHS}, () => {
workspace.appendChild(viewer);
workspace.appendChild(viewer2);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
await page.evaluate(() => {
const viewer = document.body.querySelector('perspective-viewer[name="one"]');
const workspace = document.getElementById("workspace");
workspace.removeChild(viewer);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
},
{timeout: 30000}
);
Expand All @@ -63,7 +63,7 @@ utils.with_server({paths: PATHS}, () => {
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
},
{timeout: 30000}
);
Expand All @@ -82,7 +82,7 @@ utils.with_server({paths: PATHS}, () => {
workspace.appendChild(viewer);
workspace.appendChild(viewer2);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
},
{timeout: 30000}
);
Expand All @@ -98,7 +98,7 @@ utils.with_server({paths: PATHS}, () => {
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
},
{timeout: 30000}
);
Expand All @@ -112,7 +112,7 @@ utils.with_server({paths: PATHS}, () => {
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.evaluate(async () => await document.querySelector("perspective-workspace").flush());
while ((await page.$$("perspective-workspace > perspective-viewer[updating]")).length > 0);
},
{timeout: 30000}
);
Expand Down
Loading