Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RanolP committed Feb 21, 2020
1 parent ff9a0c6 commit e30e272
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,58 @@ Read like *spike*.
1. We can write React-like Component in C++ like these syntax:

```c++
namespace Props {

#include <spaic/Prelude.hpp>

namespace props::app {
auto is_dark = fallback<bool>(false);

auto all = prop_set(is_dark);
}
namespace state::app {
auto [count, set_count] = use_state(0);

auto all = state_set(count);
}
namespace msg {
auto increment = app_msg<int>();
auto decrement = app_msg<int>();
}
public Node app() {
auto [count, set_count] = use_state(false);
ShouldRender update(Msg&& msg) {
if (increment == msg) {
set_count([](previous) {
previous + increment[0],
})
}
if (decrement == msg) {
set_count([](previous) {
previous - decrement[0],
})
}
}
Node render() {
return (
div(
className = (count > 10 && greater_than_10)
)({
"Hello! Your counter is ",
count,
button(
onClick = [] {
set_count([](previous) { previous + 1 })
}
)({
button(onClick = increment(1))({
"+1"
}),
button(
onClick = [] {
set_count([](previous) { previous + 1 })
}
)({
button(onClick = decrement(1))({
"-1"
})
})
);
}

auto app = create_component(
props::app::all,
state::app::all,

update,
render
);
```

2. :tada: We can implement React-like API on C++
Expand Down

0 comments on commit e30e272

Please sign in to comment.