MS-XAML-2017 object-mapping profile and typed View generation for Selene
Dependencies

git clone https://github.com/kkkiio/selene.git
cd selene/selene-xaml
moon install ./src/cmd/selene-xamlimport {
"KKKIIO/selene@0.37.3",
}counter/
├── moon.pkg
├── counter.mbt
├── counter.xaml
├── view_model/
│ ├── moon.pkg
│ ├── types.mbt
│ └── pkg.generated.mbti
└── view/
├── moon.pkg
├── view.generated.mbt
├── view.generated.mbt.map.json
└── pkg.generated.mbtiflowchart LR
Model["Domain Model"] --> UI["UI package"]
VM["ViewModel package"] --> UI
VM --> MBTI["moon info: .mbti"]
XAML["XAML"] --> Generator["selene-xaml"]
MBTI --> Generator
Generator --> View["Generated View package"]
UI -->|"ViewModel value"| View
View -->|"Typed Action"| UI
View --> Host["Selene xaml_view"]pub fn emphasize(label : String) -> String {
"[ " + label + " ]"
}<!-- counter.xaml -->
<Flex xmlns="urn:selene:xaml:ui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModel="moonbit:your_game/counter/view_model"
x:Class="CounterView" DataType="viewModel:CounterViewModel"
Direction="Column" Gap="12" Padding="16">
<Text Text="{Binding Path=label, Converter={x:Static viewModel:emphasize}}"
FontSize="24" Color="#f0ddbd" />
<Button x:Name="increment" OnClick="increment">
<Text Text="+1" Color="#f0ddbd" />
</Button>
</Flex>moon -C your_game info counter/view_model --target js
selene-xaml generate \
your_game/counter/counter.xaml \
--mbti your_game/counter/view_model/pkg.generated.mbti \
--out-dir your_game/counter/viewlet entity = @entity.Entity()
@counter_view.CounterView::mount(
entity,
@view_model.CounterViewModel::{ label: "0" },
)
for envelope in @event.EventReader().read(@counter_view.action_event_bus) {
match envelope.action {
Increment => {
let model = @counter_view.CounterView::view_models()[entity]
model.label = "1"
@counter_view.CounterView::refresh_label(entity)
}
}
}
@visibility.visibilities()[entity] = @visibility.Hidden
@visibility.visibilities()[entity] = @visibility.Visible
@counter_view.CounterView::unmount(entity)
entity.destroy()MS-XAML-2017 object-mapping profile and typed View generation for Selene
Dependencies