Skip to content

Commit 6a93662

Browse files
committed
Fixes + cleanup.
1 parent 35cea00 commit 6a93662

9 files changed

Lines changed: 52 additions & 69 deletions

File tree

‎include/react/detail/graph_impl.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,32 @@ void ReactGraph::EnqueueTransaction(F&& func, SyncPoint::Dependency dep, Transac
216216
transactionQueue_.Push(std::forward<F>(func), std::move(dep), flags);
217217
}
218218

219+
///////////////////////////////////////////////////////////////////////////////////////////////////
220+
/// GroupInternals
221+
///////////////////////////////////////////////////////////////////////////////////////////////////
222+
class GroupInternals
223+
{
224+
public:
225+
GroupInternals() :
226+
graphPtr_( std::make_shared<ReactGraph>() )
227+
{ }
228+
229+
GroupInternals(const GroupInternals&) = default;
230+
GroupInternals& operator=(const GroupInternals&) = default;
231+
232+
GroupInternals(GroupInternals&&) = default;
233+
GroupInternals& operator=(GroupInternals&&) = default;
234+
235+
auto GetGraphPtr() -> std::shared_ptr<ReactGraph>&
236+
{ return graphPtr_; }
237+
238+
auto GetGraphPtr() const -> const std::shared_ptr<ReactGraph>&
239+
{ return graphPtr_; }
240+
241+
private:
242+
std::shared_ptr<ReactGraph> graphPtr_;
243+
};
244+
219245
/****************************************/ REACT_IMPL_END /***************************************/
220246

221247
#endif // REACT_DETAIL_PROPAGATION_H_INCLUDED

‎include/react/detail/observer_nodes.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SyncedEventObserverNode : public ObserverNode
150150
return UpdateResult::unchanged;
151151

152152
apply([this] (const auto& ... syncs)
153-
{ func_(EventRange<E>( GetInternals(this->subject_).Events() ), GetInternals(syncs).Value() ...); }, syncHolder_);
153+
{ func_(GetInternals(this->subject_).Events(), GetInternals(syncs).Value() ...); }, syncHolder_);
154154

155155
return UpdateResult::unchanged;
156156
}

‎include/react/detail/state_nodes.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ class ObjectStateNode : public StateNode<ObjectContext<S>>
346346
{
347347
public:
348348
ObjectStateNode(const Group& group, S&& obj, const std::initializer_list<NodeId>& memberIds) :
349-
ObjectStateNode::StateNode( group, std::move(obj) )
349+
ObjectStateNode::StateNode( group, &object_ ),
350+
object_( std::move(obj) )
350351
{
351352
this->RegisterMe();
352353

@@ -356,7 +357,7 @@ class ObjectStateNode : public StateNode<ObjectContext<S>>
356357
{
357358
REACT_EXPAND_PACK(memberIds_.push_back(GetInternals(members).GetNodeId()));
358359
REACT_EXPAND_PACK(this->AttachToMe(GetInternals(members).GetNodeId()));
359-
}, this->Value().GetObject().GetReactiveMembers());
360+
}, object_.GetReactiveMembers());
360361
}
361362
else
362363
{
@@ -372,16 +373,18 @@ class ObjectStateNode : public StateNode<ObjectContext<S>>
372373

373374
template <typename ... Us>
374375
ObjectStateNode(InPlaceTag, const Group& group, Us&& ... args) :
375-
ObjectStateNode::StateNode( in_place, group, group, std::forward<Us>(args) ... )
376+
ObjectStateNode::StateNode( group, &object_ ),
377+
object_( group, std::forward<Us>(args) ... )
376378
{
377379
this->RegisterMe();
378380

379381
apply([this] (const auto& ... members)
380-
{ REACT_EXPAND_PACK(memberIds_.push_back(GetInternals(members).GetNodeId())); }, this->Value().GetObject().GetReactiveMembers());
382+
{ REACT_EXPAND_PACK(memberIds_.push_back(GetInternals(members).GetNodeId())); }, object_.GetReactiveMembers());
381383
}
382384

383385
~ObjectStateNode()
384386
{
387+
// TODO: This must happen inside of the node
385388
for (NodeId id : memberIds_)
386389
this->DetachFromMe(id);
387390

@@ -394,6 +397,7 @@ class ObjectStateNode : public StateNode<ObjectContext<S>>
394397
}
395398

396399
private:
400+
S object_;
397401
std::vector<NodeId> memberIds_;
398402
};
399403

‎include/react/group.h‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,6 @@
2020
#include "react/detail/graph_interface.h"
2121
#include "react/detail/graph_impl.h"
2222

23-
/***************************************/ REACT_IMPL_BEGIN /**************************************/
24-
25-
///////////////////////////////////////////////////////////////////////////////////////////////////
26-
/// GroupInternals
27-
///////////////////////////////////////////////////////////////////////////////////////////////////
28-
class GroupInternals
29-
{
30-
using GraphType = REACT_IMPL::ReactGraph;
31-
32-
public:
33-
GroupInternals() :
34-
graphPtr_( std::make_shared<GraphType>() )
35-
{ }
36-
37-
GroupInternals(const GroupInternals&) = default;
38-
GroupInternals& operator=(const GroupInternals&) = default;
39-
40-
GroupInternals(GroupInternals&&) = default;
41-
GroupInternals& operator=(GroupInternals&&) = default;
42-
43-
auto GetGraphPtr() -> std::shared_ptr<GraphType>&
44-
{ return graphPtr_; }
45-
46-
auto GetGraphPtr() const -> const std::shared_ptr<GraphType>&
47-
{ return graphPtr_; }
48-
49-
private:
50-
std::shared_ptr<GraphType> graphPtr_;
51-
};
52-
53-
/****************************************/ REACT_IMPL_END /***************************************/
54-
5523
/*****************************************/ REACT_BEGIN /*****************************************/
5624

5725
///////////////////////////////////////////////////////////////////////////////////////////////////

‎include/react/state.h‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class State : protected REACT_IMPL::StateInternals<S>
3939
static State Create(F&& func, const State<T1>& dep1, const State<Ts>& ... deps)
4040
{ return CreateFuncNode(dep1.GetGroup(), std::forward<F>(func), dep1, deps ...); }
4141

42+
// Construct with constant value
43+
template <typename T>
44+
static State Create(const Group& group, T&& init)
45+
{ return CreateFuncNode(group, [value = std::move(init)] { return value; }); }
46+
4247
State() = default;
4348

4449
State(const State&) = default;
@@ -292,8 +297,11 @@ class ObjectContext
292297
ObjectContext(ObjectContext&&) = default;
293298
ObjectContext& operator=(ObjectContext&&) = default;
294299

300+
S& GetObject()
301+
{ return *objectPtr_; }
302+
295303
const S& GetObject() const
296-
{ return object_; }
304+
{ return *objectPtr_; }
297305

298306
template <typename U>
299307
const U& Get(const State<U>& member) const
@@ -305,11 +313,11 @@ class ObjectContext
305313

306314
private:
307315
template <typename ... Us>
308-
explicit ObjectContext(Us&& ... args) :
309-
object_( std::forward<Us>(args) ... )
316+
explicit ObjectContext(S* objectPtr) :
317+
objectPtr_( objectPtr )
310318
{ }
311319

312-
S object_;
320+
S* objectPtr_;
313321

314322
template <typename U>
315323
friend class impl::StateNode;
@@ -345,6 +353,9 @@ class ObjectState : public State<ObjectContext<S>>
345353
ObjectState(ObjectState&&) = default;
346354
ObjectState& operator=(ObjectState&&) = default;
347355

356+
S* operator->()
357+
{ return &this->Value().GetObject(); }
358+
348359
protected:
349360
ObjectState(std::shared_ptr<REACT_IMPL::StateNode<ObjectContext<S>>>&& nodePtr) :
350361
ObjectState::State( std::move(nodePtr) )

‎project/msvc/CppReact.sln‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4_Benchmarks", "4_Benchmark
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2_Tests", "2_Tests", "{3F97AA87-0A03-4428-94C1-C9B4007C2C80}"
1919
EndProject
20-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppReactExample", "CppReactExample.vcxproj", "{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}"
21-
EndProject
2220
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicAlgorithms", "Example_BasicAlgorithms.vcxproj", "{617019A2-97BE-4A60-8EC4-3547D8C54533}"
2321
EndProject
2422
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicComposition", "Example_BasicComposition.vcxproj", "{D7B70D3B-F14D-4A85-B164-EAB88C358E85}"
@@ -67,14 +65,6 @@ Global
6765
{52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|Win32.Build.0 = Release|Win32
6866
{52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|x64.ActiveCfg = Release|x64
6967
{52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|x64.Build.0 = Release|x64
70-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|Win32.ActiveCfg = Debug|Win32
71-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|Win32.Build.0 = Debug|Win32
72-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|x64.ActiveCfg = Debug|x64
73-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|x64.Build.0 = Debug|x64
74-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|Win32.ActiveCfg = Release|Win32
75-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|Win32.Build.0 = Release|Win32
76-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|x64.ActiveCfg = Release|x64
77-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|x64.Build.0 = Release|x64
7868
{617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|Win32.ActiveCfg = Debug|Win32
7969
{617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|Win32.Build.0 = Debug|Win32
8070
{617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|x64.ActiveCfg = Debug|x64
@@ -151,7 +141,6 @@ Global
151141
{5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1} = {91AFD614-F7E6-48CE-9808-642EAF476B66}
152142
{F9115FB9-61DD-4B3C-BCE8-7D26372B05F7} = {D6F88FF5-E55C-4E65-ABBB-B4298AB84D40}
153143
{52A9EC67-C6A7-453B-AD65-F027CA07AF44} = {3F97AA87-0A03-4428-94C1-C9B4007C2C80}
154-
{CC0CD982-AE7D-4797-A122-58E6BBE70DDB} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF}
155144
{617019A2-97BE-4A60-8EC4-3547D8C54533} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF}
156145
{D7B70D3B-F14D-4A85-B164-EAB88C358E85} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF}
157146
{BD777649-97F1-4810-BF21-CB27F7672BF4} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF}

‎project/msvc/CppReact.vcxproj‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@
177177
</ItemGroup>
178178
<ItemGroup>
179179
<ClCompile Include="..\..\src\detail\graph_impl.cpp" />
180-
<ClCompile Include="..\..\src\engine\PulsecountEngine.cpp" />
181-
<ClCompile Include="..\..\src\engine\SubtreeEngine.cpp" />
182-
<ClCompile Include="..\..\src\engine\ToposortEngine.cpp" />
183180
</ItemGroup>
184181
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
185182
<ImportGroup Label="ExtensionTargets">

‎project/msvc/CppReact.vcxproj.filters‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
<Filter Include="Header Files\common">
2020
<UniqueIdentifier>{11a75126-8bfd-4693-be4b-4e06ab73450c}</UniqueIdentifier>
2121
</Filter>
22-
<Filter Include="Source Files\engine">
23-
<UniqueIdentifier>{3f444875-ab1a-4bbd-99eb-7018c930098a}</UniqueIdentifier>
24-
</Filter>
2522
<Filter Include="Source Files\detail">
2623
<UniqueIdentifier>{45678bfc-0ce5-4e47-a365-54a72d8ecb6d}</UniqueIdentifier>
2724
</Filter>
@@ -83,15 +80,6 @@
8380
</ClInclude>
8481
</ItemGroup>
8582
<ItemGroup>
86-
<ClCompile Include="..\..\src\engine\SubtreeEngine.cpp">
87-
<Filter>Source Files\engine</Filter>
88-
</ClCompile>
89-
<ClCompile Include="..\..\src\engine\ToposortEngine.cpp">
90-
<Filter>Source Files\engine</Filter>
91-
</ClCompile>
92-
<ClCompile Include="..\..\src\engine\PulsecountEngine.cpp">
93-
<Filter>Source Files\engine</Filter>
94-
</ClCompile>
9583
<ClCompile Include="..\..\src\detail\graph_impl.cpp">
9684
<Filter>Source Files\detail</Filter>
9785
</ClCompile>

‎tests/src/state_tests.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,6 @@ TEST(StateTest, Object)
475475
int height = ctx.Get(widget.height);
476476
}, st1);
477477

478-
w1.color.Set(10);
479-
w2.color.Set(20);
478+
st1->color.Set(10);
479+
st2->color.Set(20);
480480
}

0 commit comments

Comments
 (0)