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

Added flush() method to <perspective-viewer> #408

Merged
merged 1 commit into from
Feb 4, 2019
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
Added flush() method to <perspective-viewer>
  • Loading branch information
texodus committed Feb 4, 2019
commit 2088b444a77333403bdb17b6bb2fc1bd946cbaec
14 changes: 14 additions & 0 deletions packages/perspective-viewer-hypergrid/test/js/superstore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ utils.with_server({}, () => {
}, viewer);
await page.waitForSelector("perspective-viewer:not([updating])");
});

test.capture("handles flush().", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.evaluate(element => {
element.setAttribute("column-pivots", '["Category"]');
element.setAttribute("row-pivots", '["City"]');
element.flush().then(() => {
element.view.set_depth(0);
element.notifyResize();
});
}, viewer);
await page.waitForSelector("perspective-viewer:not([updating])");
});
});

describe("lazy render mode", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"superstore.html/collapses to depth smaller than viewport": "bdd25c1c40781478bd040d5816b887a6",
"regressions.html/saving a computed column does not interrupt update rendering": "da13afb4284b9c3da21ed57c6ba69301",
"empty.html/empty grids do not explode": "423ca653bbcbc21a28029c149a37b8ec",
"superstore.html/highlights invalid filter.": "e244cca8fc2278cb2477d0a46ab5331f"
"superstore.html/highlights invalid filter.": "e244cca8fc2278cb2477d0a46ab5331f",
"superstore.html/handles flush().": "a5d1bad309edf83ceef190dd19d867ec"
}
16 changes: 15 additions & 1 deletion packages/perspective-viewer/src/js/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class PerspectiveViewer extends ActionElement {
*/
@array_attribute
set "computed-columns"(computed_columns) {
this.setAttribute("updating", true);
const resolve = this._set_updating();
this._computed_column._close_computed_column();
(async () => {
if (this._table) {
Expand All @@ -156,6 +156,7 @@ class PerspectiveViewer extends ActionElement {
});
}
await this._debounce_update();
resolve();
}
this.dispatchEvent(new Event("perspective-config-update"));
this.dispatchEvent(new Event("perspective-computed-column-update"));
Expand Down Expand Up @@ -484,6 +485,19 @@ class PerspectiveViewer extends ActionElement {
await this._debounce_update();
}

/**
* Flush any pending attribute modifications to this element.
*
* @returns {Promise<void>} A promise which resolves when the current
* attribute state has been applied.
*/
async flush() {
await new Promise(setTimeout);
while (this.hasAttribute("updating")) {
await this._updating_promise;
}
}

/**
* Reset's this element's view state and attributes to default. Does not
* delete this element's `perspective.table` or otherwise modify the data
Expand Down
19 changes: 15 additions & 4 deletions packages/perspective-viewer/src/js/viewer/perspective_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PerspectiveElement extends StateElement {

async _load_table(table, computed = false) {
this.shadowRoot.querySelector("#app").classList.add("hide_message");
this.setAttribute("updating", true);
const resolve = this._set_updating();

if (this._table && !computed) {
this.removeAttribute("computed-columns");
Expand Down Expand Up @@ -167,6 +167,7 @@ export class PerspectiveElement extends StateElement {

this.filters = this.getAttribute("filters");
await this._debounce_update();
resolve();
}

async _warn_render_size_exceeded() {
Expand Down Expand Up @@ -218,7 +219,7 @@ export class PerspectiveElement extends StateElement {
const exclamation = node.shadowRoot.getElementById("row_exclamation");
const {operator, operand} = JSON.parse(node.getAttribute("filter"));
const filter = [node.getAttribute("name"), operator, operand];
if (await this._table.is_valid_filter(filter) && operand !== "") {
if ((await this._table.is_valid_filter(filter)) && operand !== "") {
filters.push(filter);
node.title = "";
operandNode.style.borderColor = "";
Expand Down Expand Up @@ -326,15 +327,25 @@ export class PerspectiveElement extends StateElement {
return Promise.all(all);
}

_set_updating() {
this.setAttribute("updating", true);
let resolve;
this._updating_promise = new Promise(_resolve => {
resolve = _resolve;
});
return resolve;
}

// setup for update
_register_debounce_instance() {
const _update = _.debounce((resolve, ignore_size_check) => {
this._new_view(ignore_size_check).then(resolve);
}, 10);
}, 0);
this._debounce_update = async ({ignore_size_check = false} = {}) => {
if (this._table) {
this.setAttribute("updating", true);
let resolve = this._set_updating();
await new Promise(resolve => _update(resolve, ignore_size_check));
resolve();
}
};
}
Expand Down