feat:add pureCallEntityMethod,avoid hook affects

This commit is contained in:
pengfei.zhou
2021-04-14 16:53:38 +08:00
committed by osborn
parent b762b9db4b
commit 009e8734b6
37 changed files with 266 additions and 209 deletions

View File

@@ -238,6 +238,26 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?:
}
}
export function pureCallEntityMethod(contextId: string, methodName: string, args?: any) {
const context = gContexts.get(contextId)
if (context === undefined) {
loge(`Cannot find context for context id:${contextId}`)
return
}
if (context.entity === undefined) {
loge(`Cannot find holder for context id:${contextId}`)
return
}
if (Reflect.has(context.entity, methodName)) {
const argumentsList: any = []
for (let i = 2; i < arguments.length; i++) {
argumentsList.push(arguments[i])
}
return Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList)
} else {
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)
}
}
type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) {

View File

@@ -276,6 +276,27 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?:
}
}
export function pureCallEntityMethod(contextId: string, methodName: string, args?: any) {
const context = gContexts.get(contextId)
if (context === undefined) {
loge(`Cannot find context for context id:${contextId}`)
return
}
if (context.entity === undefined) {
loge(`Cannot find holder for context id:${contextId}`)
return
}
if (Reflect.has(context.entity, methodName)) {
const argumentsList: any = []
for (let i = 2; i < arguments.length; i++) {
argumentsList.push(arguments[i])
}
return Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList)
} else {
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)
}
}
type ClassType<T> = new (...args: any) => T
export function jsObtainEntry(contextId: string) {

View File

@@ -27,7 +27,6 @@ export class FlowLayoutItem extends Stack {
export class FlowLayout extends Superview {
private cachedViews: Map<string, FlowLayoutItem> = new Map
private ignoreDirtyCallOnce = false
allSubviews() {
if (this.loadMoreView) {
@@ -80,18 +79,7 @@ export class FlowLayout extends Superview {
this.cachedViews.set(`${itemIdx}`, view)
return view
}
isDirty() {
if (this.ignoreDirtyCallOnce) {
this.ignoreDirtyCallOnce = false
//Ignore the dirty call once.
return false
}
return super.isDirty()
}
private renderBunchedItems(start: number, length: number) {
this.ignoreDirtyCallOnce = true;
return new Array(Math.min(length, this.itemCount - start)).fill(0).map((_, idx) => {
const listItem = this.getItem(start + idx)
return listItem.toModel()

View File

@@ -30,7 +30,6 @@ export class ListItem extends Stack {
export class List extends Superview {
private cachedViews: Map<string, ListItem> = new Map
private ignoreDirtyCallOnce = false
allSubviews() {
if (this.loadMoreView) {
@@ -83,17 +82,7 @@ export class List extends Superview {
return view
}
isDirty() {
if (this.ignoreDirtyCallOnce) {
this.ignoreDirtyCallOnce = false
//Ignore the dirty call once.
return false
}
return super.isDirty()
}
private renderBunchedItems(start: number, length: number) {
this.ignoreDirtyCallOnce = true
return new Array(Math.max(0, Math.min(length, this.itemCount - start))).fill(0).map((_, idx) => {
const listItem = this.getItem(start + idx)
return listItem.toModel()

View File

@@ -31,8 +31,6 @@ export class SlideItem extends Stack {
export class Slider extends Superview {
private cachedViews: Map<string, SlideItem> = new Map
private ignoreDirtyCallOnce = false
allSubviews() {
return this.cachedViews.values()
}
@@ -58,17 +56,7 @@ export class Slider extends Superview {
return view
}
isDirty() {
if (this.ignoreDirtyCallOnce) {
this.ignoreDirtyCallOnce = false
//Ignore the dirty call once.
return false
}
return super.isDirty()
}
private renderBunchedItems(start: number, length: number) {
this.ignoreDirtyCallOnce = true;
return new Array(Math.min(length, this.itemCount - start)).fill(0).map((_, idx) => {
const slideItem = this.getItem(start + idx)
return slideItem.toModel()