diff --git a/README.md b/README.md index 34f8c62..9353881 100644 --- a/README.md +++ b/README.md @@ -28,25 +28,23 @@ Read like *spike*. auto all = prop_set(is_dark); } namespace state::app { - auto [count, set_count] = use_state(0); + State count; auto all = state_set(count); } namespace msg { - auto increment = app_msg(); - auto decrement = app_msg(); + Message increment; + Message decrement; } - ShouldRender update(Msg&& msg) { - if (increment == msg) { - set_count([](previous) { - return previous + increment[0]; - }) + ShouldRender update() { + using namespace state::app; + using namespace msg; + if (increment) { + count += increment.get<0>(); return true; } - if (decrement == msg) { - set_count([](previous) { - return previous - decrement[0]; - }) + if (decrement) { + count -= decrement.get<0>(); return true; } return false; diff --git a/examples/Counter.cpp b/examples/Counter.cpp index 99b8556..ac13bba 100644 --- a/examples/Counter.cpp +++ b/examples/Counter.cpp @@ -6,17 +6,31 @@ namespace props::counter { auto is_dark_theme = fallback(false); } -class Counter +namespace state::counter { -private: - bool test; +State count; +} +namespace msg +{ +Message increment; +Message decrement; +} // namespace msg -public: - template - Counter(T... values) +ShouldRender update() +{ + using namespace state::counter; + using namespace msg; + if (increment) { + count += increment.get<0>(); + return true; } -}; + if (decrement) + { + count -= decrement.get<0>(); + } + return true; +} int main() { diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index b538d9e..37e7958 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -2,7 +2,7 @@ #include -namespace spaic +namespace spaic::comp { using ShouldRender = bool; template @@ -13,5 +13,5 @@ class Component { }; template -Component create_component(); +Component create_component(Props props, State state); } // namespace spaic \ No newline at end of file diff --git a/include/spaic/Message.hpp b/include/spaic/Message.hpp new file mode 100644 index 0000000..4f1671b --- /dev/null +++ b/include/spaic/Message.hpp @@ -0,0 +1,17 @@ +#pragma once + +namespace spaic::msg +{ +template +class Message +{ +public: + Message() {} + + operator bool(); + + template + std::tuple_element get(); +}; + +} // namespace spaic::msg \ No newline at end of file diff --git a/include/spaic/Prelude.hpp b/include/spaic/Prelude.hpp index b47502c..c5a987a 100644 --- a/include/spaic/Prelude.hpp +++ b/include/spaic/Prelude.hpp @@ -1,5 +1,11 @@ #pragma once #include +#include +#include +#include -using namespace spaic::props; \ No newline at end of file +using namespace spaic::props; +using namespace spaic::msg; +using namespace spaic::state; +using namespace spaic::comp; diff --git a/include/spaic/State.hpp b/include/spaic/State.hpp new file mode 100644 index 0000000..24e4ae2 --- /dev/null +++ b/include/spaic/State.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace spaic::state +{ +template +class State +{ +public: + State() {} +}; +} // namespace spaic::state \ No newline at end of file