Skip to content

Commit ee15cf4

Browse files
committed
refactor: cleanup Effect:GetProxy definition
1 parent 27c1e2a commit ee15cf4

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

cpp/Computed.hpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,7 @@ namespace reactnativecss {
2323
template<class T>
2424
class Computed {
2525
public:
26-
// Proxy passed to user callback; calling get(obs) performs obs.get(effect_)
27-
struct GetProxy {
28-
Computed *self;
29-
30-
template<class U>
31-
inline const U &operator()(Observable<U> &obs) const noexcept {
32-
return obs.get(self->effect_);
33-
}
34-
35-
// Allow dependencies on other Computed<U>
36-
template<class U>
37-
inline const U &operator()(Computed<U> &comp) const noexcept {
38-
return comp.get(self->effect_);
39-
}
40-
};
41-
42-
using ComputeFn = std::function<T(const T &prev, GetProxy &get)>;
26+
using ComputeFn = std::function<T(const T &prev, Effect::GetProxy &get)>;
4327

4428
// Factory: optional initial value (defaults to T{})
4529
template<class U = T>
@@ -65,20 +49,19 @@ namespace reactnativecss {
6549
template<class V>
6650
inline void set(V &&v) { value_->set(std::forward<V>(v)); }
6751

68-
inline void dispose() noexcept { effect_.dispose(); }
52+
inline void dispose() noexcept { effect_.dispose(); }
6953

7054
private:
7155
template<class U>
7256
explicit Computed(ComputeFn cb, U &&initial)
7357
: compute_(std::move(cb)),
7458
value_(Observable<T>::create(std::forward<U>(initial))),
75-
effect_([this] { recompute(); }) {}
59+
effect_([this](Effect::GetProxy &get) { recompute(get); }) {}
7660

7761
// Run user compute, using current value as prev and GetProxy for reads
78-
void recompute() {
79-
GetProxy g{this};
62+
void recompute(Effect::GetProxy &get) {
8063
const T &prev = value_->get();
81-
T next = compute_(prev, g);
64+
T next = compute_(prev, get);
8265
value_->set(std::move(next));
8366
}
8467

cpp/StyledComputedFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace margelo::nitro::cssnitro {
2020
ShadowTreeUpdateManager &shadowUpdates) {
2121
auto computed = reactnativecss::Computed<Styled>::create(
2222
[&styleRuleMap, classNames, componentId, &shadowUpdates](const Styled &prev,
23-
typename reactnativecss::Computed<Styled>::GetProxy &get) {
23+
typename reactnativecss::Effect::GetProxy &get) {
2424
(void) prev;
2525

2626
Styled next{};

0 commit comments

Comments
 (0)