Skip to content

Commit

Permalink
add debounce function + hide object/fn attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrelaud committed Dec 7, 2023
1 parent 49d8301 commit adc5546
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dist/lego.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ class Component extends HTMLElement {
get vstyle() { return ({ state }) => '' }

setAttribute(name, value) {
super.setAttribute(name, value);
if (typeof(value) === 'string') {
super.setAttribute(name, value);
}
const prop = toCamelCase(name);
if(this.watchProps.includes(prop)) this.render({ [prop]: value });
}
Expand All @@ -679,6 +681,11 @@ class Component extends HTMLElement {
}
}

debounce(func, timeout = 300, ...args){
clearTimeout(func.debounceTimer);
func.debounceTimer = setTimeout(() => { func.apply(this, args); }, timeout);
}

async connectedCallback() {
this.__isConnected = true;
await this.render();
Expand Down
2 changes: 1 addition & 1 deletion dist/lego.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/lego.min.js.gz
Binary file not shown.
9 changes: 8 additions & 1 deletion src/lib/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default class extends HTMLElement {
get vstyle() { return ({ state }) => '' }

setAttribute(name, value) {
super.setAttribute(name, value)
if (typeof(value) === 'string') {
super.setAttribute(name, value)
}
const prop = toCamelCase(name)
if(this.watchProps.includes(prop)) this.render({ [prop]: value })
}
Expand All @@ -48,6 +50,11 @@ export default class extends HTMLElement {
}
}

debounce(func, timeout = 300, ...args){
clearTimeout(func.debounceTimer);
func.debounceTimer = setTimeout(() => { func.apply(this, args); }, timeout);
}

async connectedCallback() {
this.__isConnected = true
await this.render()
Expand Down

0 comments on commit adc5546

Please sign in to comment.