本页提供《仓颉编程基础及应用》第1版,14.5节index.cj.macrocall文件的全文。

版权声明

本文可以在互联网上自由转载,但必须:注明出处(作者:海洋饼干叔叔)并包含指向本页面的链接。

本文不可以以纸质出版为目的进行改编、摘抄。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ohos_app_cangjie_entry

internal import ohos.base.LengthProp
internal import ohos.component.Column
internal import ohos.component.Row
internal import ohos.component.Button
internal import ohos.component.Text
internal import ohos.component.CustomView
internal import ohos.component.CJEntry
internal import ohos.component.loadNativeView
internal import ohos.state_manage.SubscriberManager
internal import ohos.state_manage.ObservedProperty
internal import ohos.state_manage.LocalStorage
import ohos.state_macro_manage.Entry
import ohos.state_macro_manage.Component
import ohos.state_macro_manage.State
import ohos.state_macro_manage.r
import std.random.Random

/* ===== Emitted by MacroCall @Entry in index.cj:20:1 ===== */
/* 20.1 */class EntryView <: CustomView {
/* 20.2 */ let messages =["Hello World", "你好,世界!", "Hei maailma", "Hola Mundo", "Привет мир", "Hallo Welt"]
/* 20.3 */ private var stateVarDecl_message_: ObservedProperty < String >= ObservedProperty < String >("stateVarDecl_message_", messages[0])
/* 20.4 */ private mut prop message: String {
/* 20.5 */ get() {
/* 20.6 */ return this.stateVarDecl_message_.get()
/* 20.7 */ }
/* 20.8 */ set(v) {
/* 20.9 */ this.stateVarDecl_message_.set(v)
/* 20.10 */ }
/* 20.11 */ }
/* 20.12 */ public func build() {
/* 20.13 */ this.observeComponentCreation({ elmtId, isInitialRender => Row { this.observeComponentCreation({ elmtId, isInitialRender => Column { this.observeComponentCreation({ elmtId, isInitialRender => Text(message).fontSize(40).height(80) })
/* 20.14 */ this.observeComponentCreation({ elmtId, isInitialRender => Button("Hello").onClick { evt => message = messages[Random().nextInt64(messages.size)] }.fontSize(40).height(80).margin(top: 100) }) }.width(100.percent) }) }.height(100.percent) })
/* 20.15 */ ()
/* 20.16 */ }
/* 20.17 */ public init(parent: Option < CustomView >, message!: Option < ObservedProperty < String >>= None, localStorage!: Option < LocalStorage >= None) {
/* 20.18 */ super(parent, localStorage)
/* 20.19 */ match(message) {
/* 20.20 */ case Some(v) => this.stateVarDecl_message_ = ObservedProperty < String >("stateVarDecl_message_", v.get())
/* 20.21 */ case _ =>()
/* 20.22 */ }
/* 20.23 */ this.stateVarDecl_message_.subscribeEx(this)
/* 20.24 */ SubscriberManager.getInstance().add(this)
/* 20.25 */ registerSelf()
/* 20.26 */ parent?.addChildById(id(), this)
/* 20.27 */ }
/* 20.28 */ public override func aboutToBeDeleted() {
/* 20.29 */ this.stateVarDecl_message_.unsubscribeEx(this)
/* 20.30 */ SubscriberManager.getInstance().delete(this)
/* 20.31 */ this.aboutToBeDeletedInternal()
/* 20.32 */ }
/* 20.33 */ func updateWithValueParams(message!: Option < String >= Option < String >.None): Unit {
/* 20.34 */ match(message) {
/* 20.35 */ case Some(v) => this.message = v
/* 20.36 */ case _ =>()
/* 20.37 */ }
/* 20.38 */ }
/* 20.39 */ public func rerender() {
/* 20.40 */ this.updateDirtyElements()
/* 20.41 */ }
/* 20.42 */ public func purgeVariableDependenciesOnElmtId(rmElmtId: Int64) {
/* 20.43 */ this.stateVarDecl_message_.purgeDependencyOnElmtId(rmElmtId)
/* 20.44 */ }
/* 20.45 */ public func forceRerender(deep!: Bool = false) {
/* 20.46 */ this.forceCompleteRerender(deep)
/* 20.47 */ }
/* 20.48 */}
/* 20.49 */
/* 20.50 */public func appEntry_0(): Bool {
/* 20.51 */ let view = EntryView(Option < CustomView >.None)
/* 20.52 */ loadNativeView(view)
/* 20.53 */}
/* 20.54 */
/* 20.55 */let a_p_1 = CJEntry.getInstance().registerEntry("EntryView", appEntry_0)
/* 20.56 */
/* ===== End of the Emit ===== */