Skip to content

Commit c99aba4

Browse files
authored
Merge pull request #1475 from finos/flicker
Upgrade `regular-table`
2 parents 52a0763 + 883f0ca commit c99aba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+808
-878
lines changed

packages/perspective-viewer-datagrid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@finos/perspective": "^0.10.0",
4242
"@finos/perspective-viewer": "^0.10.0",
4343
"chroma-js": "^1.3.4",
44-
"regular-table": "=0.4.0"
44+
"regular-table": "=0.4.1"
4545
},
4646
"devDependencies": {
4747
"@finos/perspective-test": "^0.10.0"

packages/perspective-viewer-datagrid/src/js/plugin.js

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,28 @@ import {configureEditable} from "./editing.js";
1818
import {configureSortable} from "./sorting.js";
1919
import {PLUGIN_SYMBOL} from "./plugin_menu.js";
2020

21-
function lock(body) {
22-
let lock;
23-
return async function(...args) {
24-
while (lock) {
25-
await lock;
26-
}
27-
28-
let resolve;
29-
try {
30-
lock = new Promise(x => (resolve = x));
31-
await body.apply(this, args);
32-
} finally {
33-
lock = undefined;
34-
resolve();
35-
}
36-
};
37-
}
38-
39-
async function with_safe_view(f) {
40-
try {
41-
return await f();
42-
} catch (e) {
43-
if (e.message !== "View is not initialized") {
44-
throw e;
45-
}
46-
}
47-
}
48-
4921
customElements.define(
5022
"perspective-viewer-datagrid",
5123
class extends HTMLElement {
5224
constructor() {
5325
super();
5426
this.datagrid = document.createElement("regular-table");
5527
this.datagrid.formatters = formatters;
56-
this.draw = lock(this.draw);
5728
}
5829

5930
async activate(view) {
6031
let viewer = this.parentElement;
6132
let table = viewer.table;
6233
if (!this._initialized) {
63-
this._initialized = true;
34+
this.model = await createModel(this.datagrid, table, view);
6435
this.innerHTML = "";
6536
this.appendChild(this.datagrid);
66-
this.model = await createModel(this.datagrid, table, view);
6737
configureRegularTable(this.datagrid, this.model);
6838
await configureRowSelectable.call(this.model, this.datagrid, viewer);
6939
await configureClick.call(this.model, this.datagrid, viewer);
7040
await configureEditable.call(this.model, this.datagrid, viewer);
7141
await configureSortable.call(this.model, this.datagrid, viewer);
42+
this._initialized = true;
7243
} else {
7344
await createModel(this.datagrid, table, view, this.model);
7445
}
@@ -87,39 +58,34 @@ customElements.define(
8758
}
8859

8960
async draw(view) {
90-
await with_safe_view(async () => {
91-
await this.activate(view);
92-
let viewer = this.parentElement;
93-
const draw = this.datagrid.draw({invalid_columns: true});
94-
if (!this.model._preserve_focus_state) {
95-
this.datagrid.scrollTop = 0;
96-
this.datagrid.scrollLeft = 0;
97-
deselect(this.datagrid, viewer);
98-
this.datagrid._resetAutoSize();
99-
} else {
100-
this.model._preserve_focus_state = false;
101-
}
61+
await this.activate(view);
62+
let viewer = this.parentElement;
63+
const draw = this.datagrid.draw({invalid_columns: true});
64+
if (!this.model._preserve_focus_state) {
65+
this.datagrid.scrollTop = 0;
66+
this.datagrid.scrollLeft = 0;
67+
deselect(this.datagrid, viewer);
68+
this.datagrid._resetAutoSize();
69+
} else {
70+
this.model._preserve_focus_state = false;
71+
}
10272

103-
await draw;
104-
});
73+
await draw;
10574
}
10675

10776
async update(view) {
108-
await with_safe_view(async () => {
109-
this.model._num_rows = await view.num_rows();
110-
await this.datagrid.draw();
111-
});
77+
this.model._num_rows = await view.num_rows();
78+
await this.datagrid.draw();
11279
}
11380

11481
async resize() {
115-
await with_safe_view(async () => {
116-
if (this._initialized) {
117-
await this.datagrid.draw();
118-
}
119-
});
82+
if (this._initialized) {
83+
await this.datagrid.draw();
84+
}
12085
}
12186

12287
async clear() {
88+
this.datagrid._resetAutoSize();
12389
this.datagrid.clear();
12490
}
12591

packages/perspective-viewer/src/js/custom_styles.js

Lines changed: 0 additions & 145 deletions
This file was deleted.

packages/perspective-viewer/src/js/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* A Template DOM object.
2020
*/
2121

22-
export function importTemplate(template) {
22+
function importTemplate(template) {
2323
const div = document.createElement("div");
2424
div.innerHTML = template;
2525
return Array.prototype.slice.call(div.children)[0];

packages/perspective-viewer/src/js/viewer.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,8 @@ class PerspectiveViewer extends ActionElement {
512512
this.removeAttribute("throttle");
513513
}
514514
}
515-
// Returns the throttle time, but also perform validaiton - we only want
516-
// the latter here.
517-
this._calculate_throttle_timeout();
515+
516+
this._vieux._set_render_time(this.getAttribute("throttle"));
518517
}
519518

520519
/*
@@ -607,11 +606,10 @@ class PerspectiveViewer extends ActionElement {
607606
*
608607
*/
609608
@throttlePromise
610-
async notifyResize(immediate) {
609+
async notifyResize() {
611610
const resized = await this._check_responsive_layout();
612611
if (!resized && !document.hidden && this.offsetParent) {
613-
let plugin = await this._vieux.get_plugin();
614-
await plugin.resize(immediate);
612+
await this._vieux.resize();
615613
}
616614
}
617615

packages/perspective-viewer/src/js/viewer/action_element.js

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,6 @@ import {DomElement} from "./dom_element.js";
1212
import {findExpressionByAlias, throttlePromise} from "../utils.js";
1313

1414
export class ActionElement extends DomElement {
15-
async _toggle_config(event) {
16-
if (!event || event.button !== 2) {
17-
this._show_config = !this._show_config;
18-
const panel = this.shadowRoot.querySelector("#pivot_chart_container");
19-
if (!this._show_config) {
20-
await this._pre_resize(
21-
panel.clientWidth + this._side_panel().clientWidth,
22-
panel.clientHeight + this._top_panel.clientHeight,
23-
() => {
24-
this._app.classList.remove("settings-open");
25-
this.removeAttribute("settings");
26-
},
27-
() => this.dispatchEvent(new CustomEvent("perspective-toggle-settings", {detail: this._show_config}))
28-
);
29-
} else {
30-
await this._post_resize(
31-
() => {
32-
this.toggleAttribute("settings", true);
33-
},
34-
() => {
35-
this._app.classList.add("settings-open");
36-
this.dispatchEvent(new CustomEvent("perspective-toggle-settings", {detail: this._show_config}));
37-
}
38-
);
39-
}
40-
}
41-
}
42-
4315
/**
4416
* Given a targe `width` and `height`, pre-size the plugin before modifying
4517
* the HTML to reduce visual tearing.
@@ -58,8 +30,7 @@ export class ActionElement extends DomElement {
5830
this._datavis.style.height = `${height}px`;
5931
try {
6032
if (!document.hidden && this.offsetParent) {
61-
let plugin = await this._vieux.get_plugin();
62-
await plugin.resize();
33+
await this._vieux.resize();
6334
}
6435
} finally {
6536
pre?.();
@@ -69,18 +40,6 @@ export class ActionElement extends DomElement {
6940
}
7041
}
7142

72-
async _post_resize(post, pre) {
73-
pre?.();
74-
try {
75-
if (!document.hidden && this.offsetParent) {
76-
let plugin = await this._vieux.get_plugin();
77-
await plugin.resize();
78-
}
79-
} finally {
80-
post();
81-
}
82-
}
83-
8443
/**
8544
* Display the expressions editor.
8645
*

0 commit comments

Comments
 (0)