From d3d873c886761a2deafc49f60ea31e30a5f18aad Mon Sep 17 00:00:00 2001 From: Vishnu Rajeevan Date: Tue, 27 Jan 2015 11:20:36 -0600 Subject: [PATCH] expose ReactorVar#setDependency --- .../java/io/dwak/reactiveviews/widget/MainView.java | 1 + .../main/java/io/dwak/reactor/ReactorComputation.java | 1 + reactor/src/main/java/io/dwak/reactor/ReactorVar.java | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/reactiveviews/src/main/java/io/dwak/reactiveviews/widget/MainView.java b/reactiveviews/src/main/java/io/dwak/reactiveviews/widget/MainView.java index f46ecc7..6bd6b3f 100644 --- a/reactiveviews/src/main/java/io/dwak/reactiveviews/widget/MainView.java +++ b/reactiveviews/src/main/java/io/dwak/reactiveviews/widget/MainView.java @@ -106,6 +106,7 @@ public void react(ReactorComputation reactorComputation) { mEditTextDisplay.setText(mViewModel.getEditTextValue()); } }); + Reactor.getInstance().autoRun(new ReactorComputationFunction() { @Override public void react(ReactorComputation reactorComputation) { diff --git a/reactor/src/main/java/io/dwak/reactor/ReactorComputation.java b/reactor/src/main/java/io/dwak/reactor/ReactorComputation.java index 7123048..570617f 100644 --- a/reactor/src/main/java/io/dwak/reactor/ReactorComputation.java +++ b/reactor/src/main/java/io/dwak/reactor/ReactorComputation.java @@ -21,6 +21,7 @@ public class ReactorComputation { private final int mId; private final ArrayList mInvalidateCallbacks; private final ReactorComputation mParent; + private final ReactorComputationFunction mFunction; public boolean isStopped() { diff --git a/reactor/src/main/java/io/dwak/reactor/ReactorVar.java b/reactor/src/main/java/io/dwak/reactor/ReactorVar.java index 1fb63e5..fafc502 100644 --- a/reactor/src/main/java/io/dwak/reactor/ReactorVar.java +++ b/reactor/src/main/java/io/dwak/reactor/ReactorVar.java @@ -18,16 +18,22 @@ public ReactorVar(T value) { } public T getValue() { - mDependency.depend(); + if(mDependency !=null) + mDependency.depend(); return mValue; } public void setValue(T value) { this.mValue = value; - mDependency.changed(); + if(mDependency != null) + mDependency.changed(); } public ReactorDependency getDependency() { return mDependency; } + + public void setDependency(ReactorDependency dependency) { + mDependency = dependency; + } }