Skip to content

Commit

Permalink
No throw πŸ‘πŸ‘πŸ‘πŸ‘
Browse files Browse the repository at this point in the history
  • Loading branch information
RanolP committed Mar 9, 2020
1 parent b6051f1 commit 2b8e682
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 52 deletions.
39 changes: 7 additions & 32 deletions examples/Counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VNode> wtf;
wtf.push_back("STR");
test(wtf);
// test(Incompatible{3});
}
2 changes: 2 additions & 0 deletions include/spaic-css/Stylesheet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace spaic::css
{
class Stylesheet
{
public:
Stylesheet();
std::string compile();
};
} // namespace spaic::css
5 changes: 3 additions & 2 deletions include/spaic-css/detail/CSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace spaic::css
{
template <typename... T>
spaic::css::Stylesheet css(T... params)
Stylesheet css(T... params)
{
throw "TODO: css(params)";
// TODO: css(params)
return Stylesheet();
}
} // namespace spaic::css
14 changes: 7 additions & 7 deletions include/spaic/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

#include <functional>
#include <variant>
#include <spaic/VNode.hpp>
#include <spaic/Property.hpp>
#include <spaic/State.hpp>

namespace spaic::comp
{
using ShouldRender = bool;
using Update = std::function<ShouldRender()>;
using Render = std::function<spaic::vnode::VNode()>;

class ComponentNode
{
};
class ComponentBody
{
public:
spaic::vnode::VNode operator()(spaic::vnode::VNode children...); // noexcept;
template <typename... T>
ComponentNode operator()(T... children) noexcept;
};
template <typename Props>
class Component
{
public:
Component();
template <typename... T>
ComponentBody operator()(T... args) noexcept;
};
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render);
} // namespace spaic::comp

#include <spaic/detail/Component.hpp>
16 changes: 16 additions & 0 deletions include/spaic/ComponentPart.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <functional>
#include <spaic/VNode.hpp>

namespace spaic::comp
{
using ShouldRender = bool;
using Update = std::function<ShouldRender()>;
using Render = std::function<spaic::vnode::VNode()>;

template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render);
} // namespace spaic::comp

#include <spaic/detail/ComponentPart.hpp>
1 change: 1 addition & 0 deletions include/spaic/Prelude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <spaic/Property.hpp>
#include <spaic/Message.hpp>
#include <spaic/Component.hpp>
#include <spaic/ComponentPart.hpp>
#include <spaic/State.hpp>

using namespace spaic::props;
Expand Down
9 changes: 6 additions & 3 deletions include/spaic/VNode.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <spaic/Component.hpp>
#include <variant>
#include <string>
#include <vector>
Expand All @@ -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,
Expand Down Expand Up @@ -38,9 +41,9 @@ class VNode final

public:
template <typename T>
requires std::is_convertible_v<std::remove_reference_t<T>, VNodeBase> ||
std::is_convertible_v<std::remove_reference_t<T>, std::vector<VNode>>
VNode(T &&v) noexcept(noexcept(std::is_constructible_v<decltype(_value), decltype(std::forward<T>(v))>))
requires std::is_convertible_v<std::remove_reference_t<T>, VNodeBase> ||
std::is_convertible_v<std::remove_reference_t<T>, std::vector<VNode>>
VNode(T &&v) noexcept(noexcept(std::is_constructible_v<decltype(_value), decltype(std::forward<T>(v))>))
: _value(std::forward<T>(v)) {}
};
} // namespace spaic::vnode
16 changes: 8 additions & 8 deletions include/spaic/detail/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

#include <functional>
#include <variant>
#include <spaic/VNode.hpp>
#include <spaic/Property.hpp>
#include <spaic/State.hpp>

namespace spaic::comp
{
spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) // noexcept
template <typename... T>
ComponentNode ComponentBody::operator()(T... children) noexcept
{
throw "TODO: ComponentBody::operator()(children)";
// TODO: ComponentBody::operator()(children)
return ComponentNode();
}

template <typename Props>
Component<Props>::Component()
{
}
template <typename Props>
template <typename... T>
ComponentBody Component<Props>::operator()(T... args) noexcept
{
// TODO: Component::operator()(args)
return ComponentBody();
}
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render)
{
throw "TODO: create_component(props, state, update, render)";
}
} // namespace spaic::comp
19 changes: 19 additions & 0 deletions include/spaic/detail/ComponentPart.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#pragma once

#include <functional>
#include <variant>
#include <spaic/VNode.hpp>
#include <spaic/Component.hpp>
#include <spaic/Property.hpp>
#include <spaic/State.hpp>

namespace spaic::comp
{
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render)
{
// TODO: create_component(props, state, update, render)
return Component<Props>();
}
} // namespace spaic::comp
6 changes: 6 additions & 0 deletions src/spaic-css/Stylesheet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <spaic-css/Stylesheet.hpp>

namespace spaic::css
{
Stylesheet::Stylesheet() {}
} // namespace spaic::css

0 comments on commit 2b8e682

Please sign in to comment.