提交 98c9007d 编写于 作者: fxy060608's avatar fxy060608

fix(app): insert with node json

上级 4ce481b4
......@@ -18708,9 +18708,14 @@ var serviceContext = (function (vue) {
}
}
else {
if ((process.env.NODE_ENV !== 'production')) {
console.error(formatLog(`Insert`, action, 'not found createAction'));
// 部分手机上,create 和 insert 可能不在同一批次,被分批发送
if (extras) {
action[4] = extras;
}
this.updateActions.push(action);
// if ((process.env.NODE_ENV !== 'production')) {
// console.error(formatLog(`Insert`, action, 'not found createAction'))
// }
}
break;
}
......
......@@ -213,6 +213,9 @@ export default class UniPageNode extends UniNode implements IUniPageNode {
}
} else {
// 部分手机上,create 和 insert 可能不在同一批次,被分批发送
if (extras) {
action[4] = extras as UniNodeJSON
}
this.updateActions.push(action)
// if (__DEV__) {
// console.error(formatLog(`Insert`, action, 'not found createAction'))
......
......@@ -71,7 +71,7 @@ export class UniComponent extends UniNode {
// 延迟到insert之后,再flush,确保mounted等生命周期触发正常
flushPostFlushCbs()
}
init(nodeJson: Partial<UniNodeJSON>) {
init(nodeJson: Partial<UniNodeJSON>, isCreate: boolean = true) {
const { a, e, w } = nodeJson
if (a) {
// 初始化时,先提取 wxsProps,再 setAttr
......
......@@ -45,7 +45,7 @@ export class UniElement<T extends object> extends UniNode {
this.init(nodeJson)
this.insert(parentNodeId, refNodeId)
}
init(nodeJson: Partial<UniNodeJSON>) {
init(nodeJson: Partial<UniNodeJSON>, isCreate: boolean = true) {
if (hasOwn(nodeJson, 'a')) {
this.setAttrs(nodeJson.a!)
}
......@@ -59,6 +59,8 @@ export class UniElement<T extends object> extends UniNode {
this.addWxsEvents(nodeJson.w!)
}
super.init(nodeJson)
// insert 的时候可能也会调用该 init
if (isCreate) {
watch(
this.$props,
() => {
......@@ -68,6 +70,7 @@ export class UniElement<T extends object> extends UniNode {
)
this.update(true)
}
}
setAttrs(attrs: Record<string, any>) {
// 初始化时,先提取 wxsProps,再 setAttr
this.setWxsProps(attrs)
......
......@@ -36,7 +36,7 @@ export class UniNode {
parent.appendUniChild(this)
}
}
init(nodeJson: Partial<UniNodeJSON>) {
init(nodeJson: Partial<UniNodeJSON>, isCreate: boolean = true) {
if (hasOwn(nodeJson, 't')) {
this.$.textContent = nodeJson.t as string
}
......@@ -44,7 +44,15 @@ export class UniNode {
setText(text: string) {
this.$.textContent = text
}
insert(parentNodeId: number, refNodeId: number) {
insert(
parentNodeId: number,
refNodeId: number,
nodeJson?: Partial<UniNodeJSON>
) {
// 部分性能低的手机,create 和 insert 是分开的,而 nodeJson 可能随着 insert
if (nodeJson) {
this.init(nodeJson, false)
}
const node = this.$
const parentNode = $(parentNodeId)
if (refNodeId === -1) {
......
......@@ -68,7 +68,11 @@ function onPageUpdateSync(actions: (PageAction | DictAction)[]) {
decodeNodeJson(getDict, action[5] as UniNodeJSONMinify)
)
case ACTION_TYPE_INSERT:
return $(action[1]).insert(action[2], action[3])
return $(action[1]).insert(
action[2],
action[3],
decodeNodeJson(getDict, action[4] as UniNodeJSONMinify)
)
case ACTION_TYPE_REMOVE:
return $(action[1]).remove()
case ACTION_TYPE_SET_ATTRIBUTE:
......
......@@ -240,8 +240,15 @@ export declare const initCustomDatasetOnce: () => void;
* nodeId
* parentNodeId
* refNodeId
* nodeJson
*/
export declare type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, number];
export declare type InsertAction = [
typeof ACTION_TYPE_INSERT,
number,
number,
number,
Partial<UniNodeJSON | UniNodeJSONMinify>?
];
export declare const invokeArrayFns: (fns: Function[], arg?: any) => any;
......
......@@ -58,8 +58,15 @@ export type CreateAction = [
* nodeId
* parentNodeId
* refNodeId
* nodeJson
*/
export type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, number]
export type InsertAction = [
typeof ACTION_TYPE_INSERT,
number,
number,
number,
Partial<UniNodeJSON | UniNodeJSONMinify>?
]
/**
* nodeId
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册