From 2b8e682b8dc9110591cea4bc6aa0e83e15ece3b6 Mon Sep 17 00:00:00 2001 From: RanolP Date: Mon, 9 Mar 2020 20:45:21 +0900 Subject: [PATCH] =?UTF-8?q?No=20throw=20=F0=9F=91=8F=F0=9F=91=8F?= =?UTF-8?q?=F0=9F=91=8F=F0=9F=91=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/Counter.cpp | 39 +++++--------------------- include/spaic-css/Stylesheet.hpp | 2 ++ include/spaic-css/detail/CSS.hpp | 5 ++-- include/spaic/Component.hpp | 14 ++++----- include/spaic/ComponentPart.hpp | 16 +++++++++++ include/spaic/Prelude.hpp | 1 + include/spaic/VNode.hpp | 9 ++++-- include/spaic/detail/Component.hpp | 16 +++++------ include/spaic/detail/ComponentPart.hpp | 19 +++++++++++++ src/spaic-css/Stylesheet.cpp | 6 ++++ 10 files changed, 75 insertions(+), 52 deletions(-) create mode 100644 include/spaic/ComponentPart.hpp create mode 100644 include/spaic/detail/ComponentPart.hpp diff --git a/examples/Counter.cpp b/examples/Counter.cpp index 017214b..3d5b178 100644 --- a/examples/Counter.cpp +++ b/examples/Counter.cpp @@ -43,40 +43,15 @@ VNode render() return 0; } +auto counter = create_component(props::counter::all, state::counter::all, update, render); + int main() { - std::cout << "안녕 세계는 개뿔이" << std::endl; - try - { - using namespace props::counter; - auto wtf_is_this_style = css( - width = 10.0_px); - auto counter = create_component(props::counter::all, state::counter::all, update, render); + using namespace props::counter; + auto wtf_is_this_style = css( + width = 10.0_px); + + auto rendered = counter(is_dark_theme = true)("Hello, world!", 1, 2.0); - counter(is_dark_theme = true)("Hello, world!"); - } - catch (const char *e) - { - std::cout << e << std::endl; - } return EXIT_SUCCESS; } - -// fucking test -void test(VNode node) {} - -struct Incompatible -{ - int i; -}; - -void test() -{ - using namespace props::counter; - test("STR"); - test(true); - std::vector wtf; - wtf.push_back("STR"); - test(wtf); - // test(Incompatible{3}); -} \ No newline at end of file diff --git a/include/spaic-css/Stylesheet.hpp b/include/spaic-css/Stylesheet.hpp index 6ea190f..ae36afd 100644 --- a/include/spaic-css/Stylesheet.hpp +++ b/include/spaic-css/Stylesheet.hpp @@ -6,6 +6,8 @@ namespace spaic::css { class Stylesheet { +public: + Stylesheet(); std::string compile(); }; } // namespace spaic::css diff --git a/include/spaic-css/detail/CSS.hpp b/include/spaic-css/detail/CSS.hpp index b0693fe..cb4640e 100644 --- a/include/spaic-css/detail/CSS.hpp +++ b/include/spaic-css/detail/CSS.hpp @@ -5,8 +5,9 @@ namespace spaic::css { template -spaic::css::Stylesheet css(T... params) +Stylesheet css(T... params) { - throw "TODO: css(params)"; + // TODO: css(params) + return Stylesheet(); } } // namespace spaic::css diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index a194534..c218ecf 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -2,29 +2,29 @@ #include #include -#include #include #include namespace spaic::comp { -using ShouldRender = bool; -using Update = std::function; -using Render = std::function; + +class ComponentNode +{ +}; class ComponentBody { public: - spaic::vnode::VNode operator()(spaic::vnode::VNode children...); // noexcept; + template + ComponentNode operator()(T... children) noexcept; }; template class Component { public: + Component(); template ComponentBody operator()(T... args) noexcept; }; -template -Component create_component(Props props, StateSet state, Update update, Render render); } // namespace spaic::comp #include \ No newline at end of file diff --git a/include/spaic/ComponentPart.hpp b/include/spaic/ComponentPart.hpp new file mode 100644 index 0000000..bc5f1b2 --- /dev/null +++ b/include/spaic/ComponentPart.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +namespace spaic::comp +{ +using ShouldRender = bool; +using Update = std::function; +using Render = std::function; + +template +Component create_component(Props props, StateSet state, Update update, Render render); +} // namespace spaic::comp + +#include \ No newline at end of file diff --git a/include/spaic/Prelude.hpp b/include/spaic/Prelude.hpp index 1570644..7579f80 100644 --- a/include/spaic/Prelude.hpp +++ b/include/spaic/Prelude.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include using namespace spaic::props; diff --git a/include/spaic/VNode.hpp b/include/spaic/VNode.hpp index 506f62d..75a6937 100644 --- a/include/spaic/VNode.hpp +++ b/include/spaic/VNode.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -8,6 +9,8 @@ namespace spaic::vnode { // TODO: Array of VNode should be VNode. using VNodeBase = std::variant< + spaic::comp::ComponentBody, + spaic::comp::ComponentNode, std::string, std::nullptr_t, bool, @@ -38,9 +41,9 @@ class VNode final public: template - requires std::is_convertible_v, VNodeBase> || - std::is_convertible_v, std::vector> - VNode(T &&v) noexcept(noexcept(std::is_constructible_v(v))>)) + requires std::is_convertible_v, VNodeBase> || + std::is_convertible_v, std::vector> + VNode(T &&v) noexcept(noexcept(std::is_constructible_v(v))>)) : _value(std::forward(v)) {} }; } // namespace spaic::vnode diff --git a/include/spaic/detail/Component.hpp b/include/spaic/detail/Component.hpp index 466c89a..ef9373d 100644 --- a/include/spaic/detail/Component.hpp +++ b/include/spaic/detail/Component.hpp @@ -3,17 +3,22 @@ #include #include -#include #include #include namespace spaic::comp { -spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) // noexcept +template +ComponentNode ComponentBody::operator()(T... children) noexcept { - throw "TODO: ComponentBody::operator()(children)"; + // TODO: ComponentBody::operator()(children) + return ComponentNode(); } +template +Component::Component() +{ +} template template ComponentBody Component::operator()(T... args) noexcept @@ -21,9 +26,4 @@ ComponentBody Component::operator()(T... args) noexcept // TODO: Component::operator()(args) return ComponentBody(); } -template -Component create_component(Props props, StateSet state, Update update, Render render) -{ - throw "TODO: create_component(props, state, update, render)"; -} } // namespace spaic::comp diff --git a/include/spaic/detail/ComponentPart.hpp b/include/spaic/detail/ComponentPart.hpp new file mode 100644 index 0000000..77b0b07 --- /dev/null +++ b/include/spaic/detail/ComponentPart.hpp @@ -0,0 +1,19 @@ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace spaic::comp +{ +template +Component create_component(Props props, StateSet state, Update update, Render render) +{ + // TODO: create_component(props, state, update, render) + return Component(); +} +} // namespace spaic::comp diff --git a/src/spaic-css/Stylesheet.cpp b/src/spaic-css/Stylesheet.cpp index e69de29..15690e5 100644 --- a/src/spaic-css/Stylesheet.cpp +++ b/src/spaic-css/Stylesheet.cpp @@ -0,0 +1,6 @@ +#include + +namespace spaic::css +{ +Stylesheet::Stylesheet() {} +} // namespace spaic::css \ No newline at end of file