fn main(){ auto app = App::create(); app->global<Logic>().on_magic_operation([](int value) -> int { return value * 2; }); app->global<Logic>().set_the_value(42); // ... }
可以使用双向绑定语法从全局重新公开回调或属性。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
global Logic { in-out property <int> the-value; pure callback magic-operation(int) -> int; }
component SomeComponent inherits Text { // use the global in any component text: "The magic value is:" + Logic.magic-operation(42); }
export component MainWindow inherits Window { // re-expose the global properties such that the native code // can access or modify them in-out property the-value <=> Logic.the-value; pure callback magic-operation <=> Logic.magic-operation;