ArkUI JS层

JS层代码分析

关键方法:

  • initialRender
  • observeComponentCreation
  • ViewStackProcessor.StartGetAccessRecordingFor
  • ViewStackProcessor.StopGetAccessRecording()
  • loadDocument
class Index extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__message = new ObservedPropertySimplePU('Hello World', this, "message");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.message !== undefined) {this.message = params.message;}}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__message.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__message.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get message() {return this.__message.get();}set message(newValue) {this.__message.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();Column.width('100%');Column.height('100%');if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});       this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel("更多");Button.onClick(event => {console.log("you click more");});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();        Column.pop();}rerender() {this.updateDirtyElements();}
}
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new Index(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();
"use strict";
class GreenButtonState {constructor(width) {this.width = 0;this.width = width;}
}
class GreenButton extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__greenButtonState = new SynchedPropertyObjectTwoWayPU(params.greenButtonState, this, "greenButtonState");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__greenButtonState.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__greenButtonState.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get greenButtonState() {return this.__greenButtonState.get();}set greenButtonState(newValue) {this.__greenButtonState.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel('Green Button');Button.width(this.greenButtonState.width);Button.height(40);Button.backgroundColor('#64bb5c');Button.fontColor('#FFFFFF,90%');Button.onClick(() => {if (this.greenButtonState.width < 700) {// 更新class的属性,变化可以被观察到同步回父组件this.greenButtonState.width += 60;}else {// 更新class,变化可以被观察到同步回父组件this.greenButtonState = new GreenButtonState(180);}});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();}rerender() {this.updateDirtyElements();}
}
class Index extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__message = new ObservedPropertySimplePU('Hello World', this, "message");this.__greenButtonState = new ObservedPropertyObjectPU(new GreenButtonState(180), this, "greenButtonState");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.message !== undefined) {this.message = params.message;}if (params.greenButtonState !== undefined) {this.greenButtonState = params.greenButtonState;}}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__message.purgeDependencyOnElmtId(rmElmtId);this.__greenButtonState.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__message.aboutToBeDeleted();this.__greenButtonState.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get message() {return this.__message.get();}set message(newValue) {this.__message.set(newValue);}get greenButtonState() {return this.__greenButtonState.get();}set greenButtonState(newValue) {this.__greenButtonState.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();Column.width('100%');if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Text.create(this.message);Text.fontSize(50);Text.fontWeight(FontWeight.Bold);if (!isInitialRender) {Text.pop();}ViewStackProcessor.StopGetAccessRecording();});Text.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);__Common__.create();__Common__.margin(12);if (!isInitialRender) {__Common__.pop();}ViewStackProcessor.StopGetAccessRecording();});{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new GreenButton(this, { greenButtonState: this.__greenButtonState }, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {});}ViewStackProcessor.StopGetAccessRecording();});}__Common__.pop();Column.pop();}rerender() {this.updateDirtyElements();}
}
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new Index(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();
//# sourceMappingURL=Index.js.map

添加子View

ViewPU.create(new GreenButton(this, { greenButtonState: this.__greenButtonState }, undefined, elmtId));

@Provide & @Consume

"use strict";
class CompD extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__reviewVotes = this.initializeConsume("reviewVotes", "reviewVotes");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {}aboutToBeDeleted() {this.__reviewVotes.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get reviewVotes() {return this.__reviewVotes.get();}set reviewVotes(newValue) {this.__reviewVotes.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();Column.width('50%');if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Text.create(`reviewVotes(${this.reviewVotes})`);if (!isInitialRender) {Text.pop();}ViewStackProcessor.StopGetAccessRecording();});Text.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`reviewVotes(${this.reviewVotes}), give +1`);Button.onClick(() => this.reviewVotes += 1);if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();Column.pop();}rerender() {this.updateDirtyElements();}
}
class CompC extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {}aboutToBeDeleted() {SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Row.create({ space: 5 });if (!isInitialRender) {Row.pop();}ViewStackProcessor.StopGetAccessRecording();});{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new CompD(this, {}, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {});}ViewStackProcessor.StopGetAccessRecording();});}{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new CompD(this, {}, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {});}ViewStackProcessor.StopGetAccessRecording();});}Row.pop();}rerender() {this.updateDirtyElements();}
}
class CompB extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {}aboutToBeDeleted() {SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}initialRender() {{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new CompC(this, {}, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {});}ViewStackProcessor.StopGetAccessRecording();});}}rerender() {this.updateDirtyElements();}
}
class Index extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__reviewVotes = new ObservedPropertySimplePU(0, this, "reviewVotes");this.addProvidedVar("reviewVotes", this.__reviewVotes);this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.reviewVotes !== undefined) {this.reviewVotes = params.reviewVotes;}}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {}aboutToBeDeleted() {this.__reviewVotes.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get reviewVotes() {return this.__reviewVotes.get();}set reviewVotes(newValue) {this.__reviewVotes.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`reviewVotes(${this.reviewVotes}), give +1`);Button.onClick(() => this.reviewVotes += 1);if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new CompB(this, {}, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {});}ViewStackProcessor.StopGetAccessRecording();});}Column.pop();}rerender() {this.updateDirtyElements();}
}
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new Index(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();
//# sourceMappingURL=Index.js.map

@Observed&@ObjectLink

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;return c > 3 && r && Object.defineProperty(target, key, r), r;
};
// objectLinkNestedObjects.ets
let NextID = 1;
let Bag = class Bag {constructor(size) {this.id = NextID++;this.size = size;}
};
Bag = __decorate([Observed
], Bag);
let User = class User {constructor(bag) {this.bag = bag;}
};
User = __decorate([Observed
], User);
let Book = class Book {constructor(bookName) {this.bookName = bookName;}
};
Book = __decorate([Observed
], Book);
let BookName = class BookName extends Bag {constructor(nameSize) {// 调用父类方法对nameSize进行处理super(nameSize);this.nameSize = nameSize;}
};
BookName = __decorate([Observed
], BookName);
class ViewA extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.label = 'ViewA';this.__bag = new SynchedPropertyNesedObjectPU(params.bag, this, "bag");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.label !== undefined) {this.label = params.label;}this.__bag.set(params.bag);}updateStateVars(params) {this.__bag.set(params.bag);}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__bag.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__bag.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get bag() {return this.__bag.get();}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Text.create(`ViewC [${this.label}] this.bag.size = ${this.bag.size}`);Text.fontColor('#ffffffff');Text.backgroundColor('#ff3fc4c4');Text.width(320);Text.height(50);Text.borderRadius(25);Text.margin(10);Text.textAlign(TextAlign.Center);if (!isInitialRender) {Text.pop();}ViewStackProcessor.StopGetAccessRecording();});Text.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`ViewA: this.bag.size add 1`);Button.width(320);Button.backgroundColor('#ff7fcf58');Button.margin(10);Button.onClick(() => {this.bag.size += 1;});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();Column.pop();}rerender() {this.updateDirtyElements();}
}
class ViewC extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.label = 'ViewC1';this.__bookName = new SynchedPropertyNesedObjectPU(params.bookName, this, "bookName");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.label !== undefined) {this.label = params.label;}this.__bookName.set(params.bookName);}updateStateVars(params) {this.__bookName.set(params.bookName);}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__bookName.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__bookName.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get bookName() {return this.__bookName.get();}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Row.create();if (!isInitialRender) {Row.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();Column.width(320);if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Text.create(`ViewC [${this.label}] this.bookName.size = ${this.bookName.size}`);Text.fontColor('#ffffffff');Text.backgroundColor('#ff3fc4c4');Text.width(320);Text.height(50);Text.borderRadius(25);Text.margin(10);Text.textAlign(TextAlign.Center);if (!isInitialRender) {Text.pop();}ViewStackProcessor.StopGetAccessRecording();});Text.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`ViewC: this.bookName.size add 1`);Button.width(320);Button.backgroundColor('#ff7fcf58');Button.margin(10);Button.onClick(() => {this.bookName.size += 1;console.log('this.bookName.size:' + this.bookName.size);});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();Column.pop();Row.pop();}rerender() {this.updateDirtyElements();}
}
class ViewB extends ViewPU {constructor(parent, params, __localStorage, elmtId = -1) {super(parent, __localStorage, elmtId);this.__user = new ObservedPropertyObjectPU(new User(new Bag(0)), this, "user");this.__child = new ObservedPropertyObjectPU(new Book(new BookName(0)), this, "child");this.setInitiallyProvidedValue(params);}setInitiallyProvidedValue(params) {if (params.user !== undefined) {this.user = params.user;}if (params.child !== undefined) {this.child = params.child;}}updateStateVars(params) {}purgeVariableDependenciesOnElmtId(rmElmtId) {this.__user.purgeDependencyOnElmtId(rmElmtId);this.__child.purgeDependencyOnElmtId(rmElmtId);}aboutToBeDeleted() {this.__user.aboutToBeDeleted();this.__child.aboutToBeDeleted();SubscriberManager.Get().delete(this.id__());this.aboutToBeDeletedInternal();}get user() {return this.__user.get();}set user(newValue) {this.__user.set(newValue);}get child() {return this.__child.get();}set child(newValue) {this.__child.set(newValue);}initialRender() {this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Column.create();if (!isInitialRender) {Column.pop();}ViewStackProcessor.StopGetAccessRecording();});this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);__Common__.create();__Common__.width(320);if (!isInitialRender) {__Common__.pop();}ViewStackProcessor.StopGetAccessRecording();});{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new ViewA(this, { label: 'ViewA #1', bag: this.user.bag }, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {bag: this.user.bag});}ViewStackProcessor.StopGetAccessRecording();});}__Common__.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);__Common__.create();__Common__.width(320);if (!isInitialRender) {__Common__.pop();}ViewStackProcessor.StopGetAccessRecording();});{this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);if (isInitialRender) {ViewPU.create(new ViewC(this, { label: 'ViewC #3', bookName: this.child.bookName }, undefined, elmtId));}else {this.updateStateVarsOfChildByElmtId(elmtId, {bookName: this.child.bookName});}ViewStackProcessor.StopGetAccessRecording();});}__Common__.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`ViewC: this.child.bookName.size add 10`);Button.width(320);Button.backgroundColor('#ff7fcf58');Button.margin(10);Button.onClick(() => {this.child.bookName.size += 10;console.log('this.child.bookName.size:' + this.child.bookName.size);});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`ViewB: this.user.bag = new Bag(10)`);Button.width(320);Button.backgroundColor('#ff7fcf58');Button.margin(10);Button.onClick(() => {this.user.bag = new Bag(10);});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();this.observeComponentCreation((elmtId, isInitialRender) => {ViewStackProcessor.StartGetAccessRecordingFor(elmtId);Button.createWithLabel(`ViewB: this.user = new User(new Bag(20))`);Button.width(320);Button.backgroundColor('#ff7fcf58');Button.margin(10);Button.onClick(() => {this.user = new User(new Bag(20));});if (!isInitialRender) {Button.pop();}ViewStackProcessor.StopGetAccessRecording();});Button.pop();Column.pop();}rerender() {this.updateDirtyElements();}
}
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new ViewB(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();
//# sourceMappingURL=Index.js.map

状态管理

@State

状态名使用场景基础数据对象备注
@State组件内状态同步ObservedPropertySimplePUObservedPropertyObjectPU
@Link父子双向同步SynchedPropertySimpleTwoWayPUSynchedPropertyObjectTwoWayPU
@Prop父子单向同步SynchedPropertySimplePUSynchedPropertyObjectPU
@Provide与后代组件双向同步ObservedPropertySimplePUObservedPropertyObjectPUaddProvidedVar(“xxx”)
@Consume(子)与后代组件双向同步SynchedPropertyObjectTwoWayPUSynchedPropertyObjectTwoWayPUinitializeConsume(“xxx”)
@Observed嵌套对象属性变化
@ObjectLink嵌套对象属性变化SynchedPropertyNesedObjectPU

3、父子单向同步

父组件使用@State注解变量,子组件使用@Prop注解定义自己的接收参数。当父组件修改变量时,该变量可以同步到子组件,但子组件修改此变量时不会同步到父组件。

4、与后代组件双向同步

1、@Provide注入
父组件的constructor如下

this.__reviewVotes = new ObservedPropertySimplePU(0, this, "reviewVotes");
this.addProvidedVar("reviewVotes", this.__reviewVotes);
this.setInitiallyProvidedValue(params);

2、@Consume使用
子组件的constructor如下

this.__reviewVotes = this.initializeConsume("reviewVotes", "reviewVotes");
this.setInitiallyProvidedValue(params);

3、ViewPU内部关于provide实现

//pu_view.ts
type ProvidedVarsMapPU = Map<string, ObservedPropertyAbstractPU<any>>;abstract class ViewPU extends NativeViewPartialUpdate implements IViewPropertiesChangeSubscriber {// @Provide'd variables by this class and its ancestorsprotected providedVars_: ProvidedVarsMapPU;constructor(parent: ViewPU, localStorage: LocalStorage, elmtId : number = -1) {super();//如果parent不为空,直接使用parent数据来构造一个providerVars对象,否则创建一个空对象this.providedVars_ = parent ? new Map(parent.providedVars_): new Map<string, ObservedPropertyAbstractPU<any>>();}/*** This View @Provide's a variable under given name* Call this function from the constructor of the sub class* @param providedPropName either the variable name or the alias defined as*        decorator param* @param store the backing store object for this variable (not the get/set variable!)*/protected addProvidedVar<T>(providedPropName: string, store: ObservedPropertyAbstractPU<T>) {if (this.providedVars_.has(providedPropName)) {throw new ReferenceError(`${this.constructor.name}: duplicate @Provide property with name ${providedPropName}.Property with this name is provided by one of the ancestor Views already.`);}this.providedVars_.set(providedPropName, store);}/*** Method for the sub-class to call from its constructor for resolving*       a @Consume variable and initializing its backing store*       with the SyncedPropertyTwoWay<T> object created from the*       @Provide variable's backing store.* @param providedPropName the name of the @Provide'd variable.*     This is either the @Consume decorator parameter, or variable name.* @param consumeVarName the @Consume variable name (not the*            @Consume decorator parameter)* @returns initializing value of the @Consume backing store*/protected initializeConsume<T>(providedPropName: string, consumeVarName: string): ObservedPropertyAbstractPU<T> {//因parent使用@Provide注解,在父组件构建时已经使用addProvidedVar添加过,所以此处可以get到let providedVarStore : ObservedPropertyAbstractPU<any> = this.providedVars_.get(providedPropName);if (providedVarStore === undefined) {throw new ReferenceError(`${this.constructor.name}: missing @Provide property with name ${providedPropName}.Fail to resolve @Consume(${providedPropName}).`);}const factory = <T>(source: ObservedPropertyAbstract<T>) => {const result : ObservedPropertyAbstractPU<T> = ((source instanceof ObservedPropertySimple) || (source instanceof ObservedPropertySimplePU))? new SynchedPropertyObjectTwoWayPU<T>(source, this, consumeVarName) : new SynchedPropertyObjectTwoWayPU<T>(source, this, consumeVarName);return result;};return providedVarStore.createSync(factory) as  ObservedPropertyAbstractPU<T>;}
}      

启动分析

1、从JsLoadDocument开始

//qjs_view_register.cpp
static JSValue JsLoadDocument(JSContext* ctx, JSValueConst new_target, int argc, JSValueConst* argv) {JSValue jsview = JS_DupValue(ctx, argv[0]);JSView* view = static_cast<JSView*>(UnWrapAny(jsView));auto page = QJSDeclarativeEngineInstance::GetRunningPage(ctx);CreatePageRoot(page, view);
}//qjs_view_register_impl_ng.cpp
void CreatePageRoot(RefPtr<JsAcePage>& page, JSView* view) {auto pageRootNode = AceType::DynamicCast<NG::UINode>(view->CreateViewNode());pageRootNode->MountToParent(pageNode);
}//js_view.cpp
RefPtr<AceType> JSViewPartialUpdate::CreateViewNode()
{auto node = ViewPartialUpdateModel::GetInstance()->CreateNode(std::move(info));
}//view_partial_update_model_ng.cpp
RefPtr<AceType> ViewPartialUpdateModelNG::CreateNode(NodeInfoPU&& info)
{RefPtr<NG::CustomNodeBase> customNode = NG::CustomNode::CreateCustomNode(viewId, key);
}//custom_node.cpp
void CustomNode::Build()
{Render();UINode::Build();
}void CustomNode::Render()
{auto child = renderFunction();if (child) {child->MountToParent(Claim(this));}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/34769.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

浏览器优化的案例和最佳实践

浏览器优化的案例和最佳实践 减少HTTP请求数量优化资源文件优化DOM结构提升JavaScript性能优化渲染性能移除不必要的插件和扩展监控并分析页面性能持续优化和测试除了上述的优化方式,还有一些其他的浏览器优化技巧,包括: 减少HTTP请求数量 案例:某电商网站首页有大量的图片和C…

探索Java中的多态

多态&#xff08;Polymorphism&#xff09;是面向对象编程&#xff08;OOP&#xff09;中的一个核心概念&#xff0c;它允许同一个接口或方法在不同对象上具有不同的实现方式。Java作为一种面向对象的编程语言&#xff0c;广泛地利用了多态特性来提高代码的灵活性和可扩展性。本…

精准把握时间脉络:Java日期时间处理API深度解析与实战指南

在软件开发领域&#xff0c;准确无误地处理日期和时间信息是构建稳定、可靠应用程序的关键一环。随着技术的演进&#xff0c;Java作为一门广泛应用的编程语言&#xff0c;其处理日期和时间的API也经历了显著的变化和发展&#xff0c;旨在为开发者提供更为强大、灵活且易用的工具…

httpclient并发性能问题解决

故事 前段时间进行招聘笔试&#xff0c;有这么一个问题&#xff0c;请描述实践过程中解决httpclient并发性能问题的案例。然后自己之前是有遇到过&#xff0c;但是一直没有总结&#xff0c;趁此机会总结一波。 问题 请描述实践过程中解决httpclient并发性能问题的案例。并描…

企业级低代码开发效率变革赋能业务增长

企业级低代码开发已经成为当今软件开发领域的一大趋势&#xff0c;它为企业带来了前所未有的效率变革&#xff0c;从而赋能业务增长。本文将围绕这一主题&#xff0c;深入探讨低代码开发的概念、优势以及如何在企业级应用中实现高效的低代码开发&#xff0c;以助力我国企业实现…

Linux网络 - 再谈、详谈UDP和TCP协议

文章目录 前言预备netstatpidofcat /etc/services 一、UDP协议UDP协议端格式UDP的缓冲区基于UDP的应用层协议 二、TCP协议1.TCP协议段格式确认应答(ACK)机制三次握手疑问1 最后一次客户端发给服务端的ACK请求怎么保证服务端能够收到&#xff1f; 四次挥手疑问2 为什么挥手是四次…

51单片机STC89C52RC——4.1 矩阵按键(数码管显示按键值)

目录 目录 目的 一&#xff0c;STC单片机模块 二&#xff0c;矩阵按键模块 2.1 针脚定义 ​编辑 2.2 矩阵按键位置 2.3 如何理解按键按下后针脚的高低电平 2.3.1 错误理解1 2.3.2 错误理解2 2.3.3 正确判定按下的是那个按键的逻辑 2.3.4 判定按键按下的依次扫描程…

2024年618有哪些必囤的好物?2024年618好物排行榜

618年中大促再度来临。对于购物爱好者来说&#xff0c;这无疑是一个不容错过的购物盛宴。那么&#xff0c;在这个618&#xff0c;哪些好物值得你重点关注呢&#xff1f;我特地整理了一份推荐清单&#xff0c;这些产品不仅经过我的亲身体验&#xff0c;更以其出色的实用性和高性…

MySQL中结构化系统变量介绍

结构化变量&#xff08;structured variable&#xff09;与常规系统变量&#xff08;regular system variable&#xff09;之间的两个主要区别。以下是这两个区别的详细解释&#xff1a; 值是一个结构&#xff1a; 常规系统变量通常存储单一的值&#xff0c;比如一个整数、浮…

【XCharts插件】4-2、配置项手册(v3.0)

推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址QQ群:398291828大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。 一、前言 XCharts插件是一款基于UGUI的功能强大、易用、参数可配置的数据可视化图表插件。 【Unity3D…

硬件基础知识——自学习梳理

计算机存储分为闪存和永久性存储。 硬盘&#xff08;永久存储&#xff09;主要分为机械磁盘和固态硬盘。 机械磁盘主要靠磁颗粒的正负极方向来存储0或1&#xff0c;且机械磁盘没有使用寿命。 固态硬盘就有使用寿命了&#xff0c;大概支持30w次的读写操作。 闪存使用的是电容…

使用js实现excel的读取展示以及导出

代码 <!DOCTYPE html> <html lang"zh"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title><link rel"st…

liunx打开谷歌报错

liunx打开谷歌报错[48526:48526:0624/173553.311113:ERROR:zygote_host_impl_linux.cc(99)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. 这个错误信息表明你尝试以root用户身份运行Chrome浏览器&#xff0c;但是没有使用–no-san…

现身说法,AI小白的大模型学习过程

导读 写这篇文章的初衷&#xff1a;作为一个AI小白&#xff0c;把我自己学习大模型的学习路径还原出来&#xff0c;包括理解的逻辑、看到的比较好的学习材料&#xff0c;通过一篇文章给串起来&#xff0c;对大模型建立起一个相对体系化的认知&#xff0c;才能够在扑面而来的大…

idea 突然 Cannot resolve symbol ‘xxx‘

解决一&#xff1a;关闭 idea&#xff0c;在文件夹中找到代码所在位置&#xff0c;删除 .idea 文件夹重新打开项目就可以了 解决二&#xff1a;检查 jdk 版本 解决三&#xff1a;保存重要文件&#xff0c;重新下载项目代码

接口防篡改+防重放攻击

接口防止重放攻击&#xff1a;重放攻击是指攻击者截获了一次有效请求(如交易请求),并在之后的时间里多次发送相同的请求&#xff0c;从而达到欺骗系统的目的。为了防止重放攻击&#xff0c;通常需要在系统中引入一种机制&#xff0c;使得每个请求都有一个唯一的标识符(如时间戳…

深度学习训练基于Pod和RDMA

目录 ​编辑 引言 RDMA技术概述 InfiniBand iWARP RoCE Pod和容器化环境 深度学习训练与RDMA结合 MPI和RDMA 深度学习框架与RDMA 实战&#xff1a;基于Pod和RDMA的深度学习训练 环境准备 步骤 YAML 性能和优势 结论 引言 随着深度学习在人工智能领域的快速发展…

Linux下命令行文件创建删除、目录创建删除

在Linux命令行下&#xff0c;文件和目录的创建与删除是通过一系列基础命令完成的&#xff0c;这些命令对于日常的系统管理和文件操作至关重要。 下面将详细介绍这些命令的功能和使用方法。 普通文件的创建与删除 创建文件 touch命令&#xff1a;主要用于创建一个空文件&…

使用Tauri+vite+koa2+mysql开发了一款待办效率应用

&#x1f389;使用Taurivitekoa2mysql开发了一款待办效率应用 &#x1f4dd;项目概述 这是一个基于taurivite的应用&#xff0c;它采用了一些最新的前端技术&#xff0c;包括 Tauri、Vue3、Vite5、koa2 和 mysql。它提供了丰富的效率管理工具。 应用地址&#xff1a;https:/…

Laravel依赖注入全解析:构建灵活应用的秘诀

Laravel依赖注入全解析&#xff1a;构建灵活应用的秘诀 引言 Laravel框架以其优雅的语法和强大的功能著称&#xff0c;其中依赖注入&#xff08;Dependency Injection&#xff09;是其核心特性之一。依赖注入是一种设计模式&#xff0c;用于减少代码间的耦合度&#xff0c;提…