Add debug markers to react::value internal nodes to track their lifetime
This commit is contained in:
parent
367f82a01f
commit
9f063218bf
3 changed files with 55 additions and 0 deletions
15
libs/react/include/psemek/react/debug.hpp
Normal file
15
libs/react/include/psemek/react/debug.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/react/value.hpp>
|
||||||
|
|
||||||
|
namespace psemek::react
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
value<T> debug_marker(std::string marker, value<T> value)
|
||||||
|
{
|
||||||
|
value.node(detail::internal_tag{})->debug_marker = std::move(marker);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace psemek::react
|
namespace psemek::react
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +21,8 @@ namespace psemek::react
|
||||||
struct forever_tag
|
struct forever_tag
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
void on_node_destroyed(std::string const & debug_marker);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct node
|
struct node
|
||||||
{
|
{
|
||||||
|
|
@ -31,12 +34,19 @@ namespace psemek::react
|
||||||
std::optional<T> cached_value;
|
std::optional<T> cached_value;
|
||||||
std::vector<std::shared_ptr<void>> subscriptions;
|
std::vector<std::shared_ptr<void>> subscriptions;
|
||||||
|
|
||||||
|
std::string debug_marker;
|
||||||
|
|
||||||
T const & value()
|
T const & value()
|
||||||
{
|
{
|
||||||
if (!cached_value)
|
if (!cached_value)
|
||||||
cached_value.emplace(getter());
|
cached_value.emplace(getter());
|
||||||
return *cached_value;
|
return *cached_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~node()
|
||||||
|
{
|
||||||
|
on_node_destroyed(debug_marker);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -47,8 +57,15 @@ namespace psemek::react
|
||||||
util::signal<> internal_signal;
|
util::signal<> internal_signal;
|
||||||
util::signal<> external_signal;
|
util::signal<> external_signal;
|
||||||
|
|
||||||
|
std::string debug_marker;
|
||||||
|
|
||||||
void value()
|
void value()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
~node()
|
||||||
|
{
|
||||||
|
on_node_destroyed(debug_marker);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
@ -125,6 +142,11 @@ namespace psemek::react
|
||||||
return node_->internal_signal.subscribe(std::move(subscriber));
|
return node_->internal_signal.subscribe(std::move(subscriber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<detail::node<T>> node(detail::internal_tag)
|
||||||
|
{
|
||||||
|
return node_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<detail::node<T>> node_;
|
std::shared_ptr<detail::node<T>> node_;
|
||||||
|
|
||||||
|
|
|
||||||
18
libs/react/source/value.cpp
Normal file
18
libs/react/source/value.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <psemek/react/value.hpp>
|
||||||
|
#include <psemek/util/unused.hpp>
|
||||||
|
|
||||||
|
namespace psemek::react
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
void on_node_destroyed(std::string const & debug_marker)
|
||||||
|
{
|
||||||
|
// Can put a breakpoint here to track destruction of specific nodes
|
||||||
|
unused(debug_marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue