TASK: #105604-(perf)optimize indicator-page-point.

This commit is contained in:
wangchangqi 2022-08-23 09:21:40 +08:00
parent 3479d88c0b
commit 981577f4ff
2 changed files with 23 additions and 21 deletions

View File

@ -1,4 +1,4 @@
import {html, css, LitElement} from 'lit'
import {html, css, LitElement, PropertyValueMap} from 'lit'
import {customElement, property} from 'lit/decorators.js'
import {classMap} from 'lit/directives/class-map.js'
@ -9,16 +9,13 @@ export class IndicatorPagePoint extends LitElement {
@property({type: Boolean, reflect: true}) edit = false
@property({type: Boolean, reflect: true}) column = false
updated() {
this.checkProperties()
}
#firstRender = true
protected shouldUpdate(
_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>
): boolean {
let isShouldUpdate = true
/**
*
*
* hasChange 访 this
*/
checkProperties(): void {
if (this.total < 1) {
console.warn(
'indicator total setted a error num: ',
@ -26,6 +23,7 @@ export class IndicatorPagePoint extends LitElement {
' will be resetted 1'
)
this.total = 1
isShouldUpdate = false
} else if (this.total > 15) {
console.warn(
'indicator total setted a error num: ',
@ -33,6 +31,7 @@ export class IndicatorPagePoint extends LitElement {
' will be resetted 15'
)
this.total = 15
isShouldUpdate = false
}
if (this.index < 1) {
@ -42,6 +41,7 @@ export class IndicatorPagePoint extends LitElement {
' will be resetted 1'
)
this.index = 1
isShouldUpdate = false
} else if (this.index > this.total) {
console.warn(
'indicator index setted a error num: ',
@ -50,7 +50,14 @@ export class IndicatorPagePoint extends LitElement {
this.total
)
this.index = this.total
isShouldUpdate = false
}
if (this.#firstRender === true) {
this.#firstRender = false
return true
}
return isShouldUpdate
}
render() {

View File

@ -35,15 +35,8 @@ export class PanelIndicators extends LitElement {
case 'index--':
this.index--
break
case 'edit-add':
Array.prototype.forEach.call(this.myindicators, (e) =>
e.setAttribute('edit', '')
)
break
case 'edit-remove':
Array.prototype.forEach.call(this.myindicators, (e) =>
e.removeAttribute('edit')
)
case 'toggle-edit':
this.edit = !this.edit
break
}
}
@ -81,14 +74,14 @@ export class PanelIndicators extends LitElement {
<button data-action="total--" @click=${this}>total--</button>
<button data-action="index++" @click=${this}>index++</button>
<button data-action="index--" @click=${this}>index--</button>
<button data-action="edit-add" @click=${this}>add edit</button>
<button data-action="edit-remove" @click=${this}>remove edit</button>
<button data-action="toggle-edit" @click=${this}>toggle edit</button>
</div>
</div>
<indicator-page-point
class="myindicator"
total=${this.total}
index=${this.index}
?edit=${this.edit}
></indicator-page-point>
<div>
<div>
@ -96,12 +89,14 @@ export class PanelIndicators extends LitElement {
class="myindicator"
total=${this.total}
index=${this.index}
?edit=${this.edit}
column
></indicator-page-point>
<indicator-page-point
class="myindicator"
total=${this.total}
index=${this.index}
?edit=${this.edit}
column
></indicator-page-point>
</div>