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

View File

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