Support creating react::source with an immediate subscriber
This commit is contained in:
parent
9f0179a86a
commit
e21692743c
2 changed files with 27 additions and 0 deletions
|
|
@ -22,6 +22,15 @@ namespace psemek::react
|
||||||
set(std::move(x));
|
set(std::move(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source(T x, typename util::signal<T>::subscriber subscriber)
|
||||||
|
: source(std::move(x))
|
||||||
|
{
|
||||||
|
subscription_token_ = this->subscribe(std::move(subscriber));
|
||||||
|
}
|
||||||
|
|
||||||
|
source & operator = (source const &) = default;
|
||||||
|
source & operator = (source &&) = default;
|
||||||
|
|
||||||
void set(T x) const
|
void set(T x) const
|
||||||
{
|
{
|
||||||
this->node_->cached_value = std::nullopt;
|
this->node_->cached_value = std::nullopt;
|
||||||
|
|
@ -55,6 +64,9 @@ namespace psemek::react
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
typename util::signal<T>::subscription_token subscription_token_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -68,11 +80,23 @@ namespace psemek::react
|
||||||
: value<void>(detail::internal_tag{}, std::make_shared<detail::node<void>>())
|
: value<void>(detail::internal_tag{}, std::make_shared<detail::node<void>>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
source(util::signal<void>::subscriber subscriber)
|
||||||
|
: source()
|
||||||
|
{
|
||||||
|
subscribtion_token_ = subscribe(std::move(subscriber));
|
||||||
|
}
|
||||||
|
|
||||||
|
source & operator = (source const &) = default;
|
||||||
|
source & operator = (source &&) = default;
|
||||||
|
|
||||||
void set() const
|
void set() const
|
||||||
{
|
{
|
||||||
this->node_->internal_signal();
|
this->node_->internal_signal();
|
||||||
this->node_->external_signal();
|
this->node_->external_signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
util::signal<void>::subscription_token subscribtion_token_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,9 @@ namespace psemek::react
|
||||||
: node_(node)
|
: node_(node)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
value & operator = (value const &) = default;
|
||||||
|
value & operator = (value &&) = default;
|
||||||
|
|
||||||
explicit operator bool() const
|
explicit operator bool() const
|
||||||
{
|
{
|
||||||
return static_cast<bool>(node_);
|
return static_cast<bool>(node_);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue