Skip to content

fixed animation issue by not recreating the entire stylesheet - #1391

Closed
marttop wants to merge 2 commits into
gridstack:developfrom
marttop:develop
Closed

marttop wants to merge 2 commits into
gridstack:developfrom
marttop:develop

Conversation

@marttop

@marttop marttop commented Sep 30, 2020 •

Copy link
Copy Markdown

Description

fixed animation issue by not recreating the entire stylesheet on every event but only when it's needed.

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

@marttop marttop mentioned this pull request Sep 30, 2020
@marttop marttop changed the title fixed animation issue by not recreating the entire stylesheet on ever… fixed animation issue by not recreating the entire stylesheet on ever… Sep 30, 2020
@marttop marttop changed the title fixed animation issue by not recreating the entire stylesheet on ever… fixed animation issue by not recreating the entire stylesheet Sep 30, 2020
Deleted forgotten commented console logs.

@adumesny adumesny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for doing this, but this is wrong approach to check for existing styles. we know what the prev max was and can append only new styles instead.
And yes we should never delete the file UNLESS there are some styles which are column based or something that can change like margin. I haven't looked carefully on what is inserted in there...

Comment thread src/gridstack.ts
private _initStyles(): GridStack {
if (this._stylesId) {
Utils.removeStylesheet(this._stylesId);
if (!this._stylesId) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move that create code to first line of _updateStyles() and change constructor to call it instead. Remove _initStyles()

Comment thread src/utils.ts
if (!el || !el.parentNode) return;
el.parentNode.removeChild(el);
}
static getAllSelectors(sheet: CSSStyleSheet) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type, method description

Comment thread src/utils.ts
var ret = [];
var rules = sheet.cssRules;
// console.log(JSON.stringify(rules));
for(var i = 0; i < rules.length; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for () spacing please, same with if ()

Comment thread src/utils.ts
return ret;
}

static hasCSSRule(sheet: CSSStyleSheet, selector: string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment thread src/utils.ts
sheet.addRule(selector, rules);
} else if (typeof sheet.insertRule === 'function') {
sheet.insertRule(`${selector}{${rules}}`);
if(!Utils.hasCSSRule(sheet, selector)){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't know what we need to check for existing rules... I mean we know what the previous max was so we can append new styles only. Also the original one are created once so they don't need this.

Comment thread src/gridstack.ts
let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
this._styles = Utils.createStylesheet(this._stylesId, styleLocation);
if (this._styles !== null) {
this._styles._max = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should NEVER happen but on creation, then we can use the max to figure new styles that need to be appended.
you don't need to check for existing styles.

@adumesny

adumesny commented Oct 1, 2020 •

Copy link
Copy Markdown
Member

Also please combine all those into 1 commit please - you can git rebase -i HEAD~6 (or how many commits you've made) and squash them into one and git push -f your changes up.

@adumesny

adumesny commented Oct 1, 2020

Copy link
Copy Markdown
Member

and looks like changing the cellHeight() or margin() needs to delete and re-create, and that's the only time, otherwise we append new style to initial creation that are past max (no need to check for existing).

@marttop marttop closed this Oct 1, 2020
@marttop marttop mentioned this pull request Oct 2, 2020
1 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants