From e30e2723eba8de021c866ed175f4392389303345 Mon Sep 17 00:00:00 2001 From: RanolP Date: Fri, 21 Feb 2020 12:32:17 +0900 Subject: [PATCH] Update README.md --- README.md | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ba3888f..bc1937d 100644 --- a/README.md +++ b/README.md @@ -20,34 +20,58 @@ Read like *spike*. 1. We can write React-like Component in C++ like these syntax: ```c++ - namespace Props { - + #include + + namespace props::app { + auto is_dark = fallback(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(); + auto decrement = app_msg(); } - 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++