diff --git a/examples/Counter.cpp b/examples/Counter.cpp index ac13bba..967ebe3 100644 --- a/examples/Counter.cpp +++ b/examples/Counter.cpp @@ -5,11 +5,15 @@ namespace props::counter { auto is_dark_theme = fallback(false); -} + +auto all = is_dark_theme; +} // namespace props::counter namespace state::counter { State count; -} + +auto all = count; +} // namespace state::counter namespace msg { Message increment; @@ -22,19 +26,27 @@ ShouldRender update() using namespace msg; if (increment) { - count += increment.get<0>(); + *count += increment.get<0>(); return true; } if (decrement) { - count -= decrement.get<0>(); + *count -= decrement.get<0>(); } return true; } +VNode render() +{ + return 0; +} + +auto counter = create_component(props::counter::all, state::counter::all, update, render); + int main() { using namespace props::counter; + counter(is_dark_theme = true)("Hello, world!"); // new Counter(is_dark_theme = true); // Counter{is_dark_theme = true}; // Counter(is_dark_theme = true); diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index 37e7958..a409556 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -1,17 +1,30 @@ #pragma once #include +#include +#include +#include +#include namespace spaic::comp { using ShouldRender = bool; -template -using Update = std::function(Msg)->ShouldRender; +using Update = std::function; +using Render = std::function; -template +class ComponentBody; +template class Component { +public: + template + ComponentBody operator()(T... args) noexcept; }; -template -Component create_component(Props props, State state); -} // namespace spaic \ No newline at end of file +class ComponentBody +{ +public: + spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept; +}; +template +Component create_component(Props props, StateSet state, Update update, Render render); +} // namespace spaic::comp \ No newline at end of file diff --git a/include/spaic/Message.hpp b/include/spaic/Message.hpp index 4f1671b..4f20512 100644 --- a/include/spaic/Message.hpp +++ b/include/spaic/Message.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace spaic::msg { template @@ -11,7 +13,7 @@ class Message operator bool(); template - std::tuple_element get(); + typename std::tuple_element>::type get(); }; } // namespace spaic::msg \ No newline at end of file diff --git a/include/spaic/Prelude.hpp b/include/spaic/Prelude.hpp index c5a987a..1570644 100644 --- a/include/spaic/Prelude.hpp +++ b/include/spaic/Prelude.hpp @@ -9,3 +9,4 @@ using namespace spaic::props; using namespace spaic::msg; using namespace spaic::state; using namespace spaic::comp; +using namespace spaic::vnode; diff --git a/include/spaic/State.hpp b/include/spaic/State.hpp index 24e4ae2..6377c2a 100644 --- a/include/spaic/State.hpp +++ b/include/spaic/State.hpp @@ -7,5 +7,8 @@ class State { public: State() {} + + // todo: + T &operator*(); }; } // namespace spaic::state \ No newline at end of file diff --git a/include/spaic/VNode.hpp b/include/spaic/VNode.hpp new file mode 100644 index 0000000..aee0e92 --- /dev/null +++ b/include/spaic/VNode.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +namespace spaic::vnode +{ +using VNode = std::variant< + std::string, + std::nullptr_t, + bool, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + char, + signed char, + unsigned char, + wchar_t, + char16_t, + char32_t, + float, + double, + long double>; +} // namespace spaic::vnode \ No newline at end of file