-
Notifications
You must be signed in to change notification settings - Fork 13
/
js.rs
41 lines (34 loc) · 1.28 KB
/
js.rs
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
use genco::fmt;
use genco::prelude::*;
fn main() -> anyhow::Result<()> {
let react = &js::import("react", "React").into_default();
let display = &js::import("./Display", "Display").into_default();
let button_panel = &js::import("./ButtonPanel", "ButtonPanel").into_default();
let calculate = &js::import("../logic/calculate", "calculate").into_default();
let tokens = quote! {
export default class App extends $react.Component {
state = {
total: null,
next: null,
operation: null,
};
handleClick = buttonName => {
this.setState($calculate(this.state, buttonName));
};
render() {
return (
<div className="component-app">
<$display value={this.state.next || this.state.total || "0"} />
<$button_panel clickHandler={this.handleClick} />
</div>
);
}
}
};
let stdout = std::io::stdout();
let mut w = fmt::IoWriter::new(stdout.lock());
let fmt = fmt::Config::from_lang::<JavaScript>();
let config = js::Config::default();
tokens.format_file(&mut w.as_formatter(&fmt), &config)?;
Ok(())
}