1import { 2 memo, 3 __memo_context_type, 4 __memo_id_type, 5 Watch, 6 Observed, 7 Track, 8 ObjectLink, 9 State, 10 Link, 11 Prop, 12 StorageLink, 13 StorageProp, 14 AppStorage, 15 LocalStorage 16} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins 17 18import { 19 Text, 20 Column, 21 Component, 22 Entry, 23 Button, 24 ClickEvent, 25 NavDestination, 26 NavPathStack, 27 NavDestinationContext, 28 Callback 29} from '@ohos.arkui.component' 30 31import hilog from '@ohos.hilog' 32 33@Observed 34class Info { 35 public id: number = 0; 36 private name: string = ''; 37 38 constructor(id?: number) { 39 this.id = id ?? 41; 40 } 41} 42 43@Component 44struct Child { 45 @ObjectLink @Watch('onChange1') child: Info = new Info(); 46 message1: string = `change id refresh`; 47 changeValue() { 48 this.child.id += 5; 49 } 50 onChange1(propertyName: string) { 51 hilog.info(0x0000, 'watchTag', `zzq onChange1 ${this.child.id}`) 52 } 53 build() { 54 Column() { 55 Text('child id: ' + this.child.id).fontSize(20) 56 Button(this.message1).backgroundColor('#FFFF00FF') 57 .onClick((e: ClickEvent) => { 58 hilog.info(0x0000, 'testTag', 'On Click'); 59 this.changeValue() 60 }) 61 } 62 } 63} 64 65@Entry 66@Component 67export struct ObservedObjectLinkTest { 68 @State info: Info = new Info(); 69 70 message1: string = `change name refresh`; 71 message2: string = `change name not refresh`; 72 changeValue() { 73 this.info = new Info(30) 74 } 75 76 build() { 77 NavDestination() { 78 Column(undefined) { 79 Text('id: ' + this.info.id).fontSize(20) 80 Button(this.message1).backgroundColor('#FFFF00FF') 81 .onClick((e: ClickEvent) => { 82 hilog.info(0x0000, 'testTag', 'On Click'); 83 this.changeValue() 84 }) 85 Child({child: this.info}) 86 }.margin(10) 87 } 88 .title('@Observed/@ObjectLink支持基础功能观测能力') 89 } 90}