public void Deactivation() => TestZone.Run(tick => { var activation = ""; var source = Atom.Value( 0, onActive: () => activation += "S", onInactive: () => activation += "s"); var middle = Atom.Computed( () => source.Value + 1, onActive: () => activation += "M", onInactive: () => activation += "m"); var target = Atom.Computed( () => middle.Value + 1, onActive: () => activation += "T", onInactive: () => activation += "t"); target.Get(); Assert.AreEqual("", activation); var autoRun = Atom.AutoRun(() => target.Get()); Assert.AreEqual("TMS", activation); autoRun.Dispose(); Assert.AreEqual("TMS", activation); tick(0); Assert.AreEqual("TMStms", activation); });
public static IDisposable RunApp([NotNull] ViewPanel root, [NotNull] WidgetBuilder builder) { if (root == null) { throw new ArgumentNullException(nameof(root)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } IView view = root; var context = new BuildContext(null, null); var state = State.Create(context, builder); var render = Atom.AutoRun(() => root.Render(state.Value)); // ReSharper disable once ImplicitlyCapturedClosure return(new ActionDisposable(() => { render.Dispose(); if (!Engine.IsApplicationQuiting) { view.ResetSource(); } })); }
public void ObsoleteAtomsActualizedInInitialOrder() => TestZone.Run(tick => { var actualization = ""; var source = Atom.Value(1); var middle = Atom.Computed(() => { actualization += "M"; return(source.Value); }); var target = Atom.Computed(() => { actualization += "T"; source.Get(); return(middle.Value); }); var autoRun = Atom.AutoRun(() => target.Get()); Assert.AreEqual("TM", actualization); source.Value = 2; tick(0); Assert.AreEqual("TMTM", actualization); autoRun.Dispose(); });
public void NoReactivationDuringPulling() => TestZone.Run(tick => { var activation = ""; var activationSource = Atom.Computed( pull: () => 1, onActive: () => activation += "A", onInactive: () => activation += "D"); var modifiedSource = Atom.Value(1); var listener = Atom.Computed(() => activationSource.Value + modifiedSource.Value); Assert.AreEqual("", activation); var autoRun = Atom.AutoRun(() => listener.Get()); Assert.AreEqual("A", activation); modifiedSource.Value = 2; Assert.AreEqual("A", activation); tick(0); Assert.AreEqual("A", activation); autoRun.Dispose(); });
private void OnEnable() { _reaction = Atom.AutoRun(() => { Debug.Log($"Tasks left: {_todoList.UnfinishedTodoCount}"); unfinishedTodoCountText.text = $"Tasks left: {_todoList.UnfinishedTodoCount}"; }); addTodoButton.onClick.AddListener(AddTodo); }
public void AutoUnsubscribed_Reaction() => TestZone.Run(tick => { var source = Atom.Value(1); var middle = Atom.Computed(() => source.Value + 1); var target = Atom.Computed(() => middle.Value + source.Value); var run = Atom.AutoRun(() => target.Get()); Assert.AreEqual(2, source.SubscribersCount()); Assert.AreEqual(1, middle.SubscribersCount()); Assert.AreEqual(1, target.SubscribersCount()); run.Dispose(); tick(0); Assert.AreEqual(0, source.SubscribersCount()); Assert.AreEqual(0, middle.SubscribersCount()); Assert.AreEqual(0, target.SubscribersCount()); });
public void NoReactivationDuringModification() => TestZone.Run(tick => { var activation = ""; var atom = Atom.Value(1, onActive: () => activation += "A", onInactive: () => activation += "D"); Assert.AreEqual("", activation); var autoRun = Atom.AutoRun(() => atom.Get()); Assert.AreEqual("A", activation); atom.Value = 2; Assert.AreEqual("A", activation); tick(0); Assert.AreEqual("A", activation); autoRun.Dispose(); });
public void AutoUnsubscribed_MultiReaction() => TestZone.Run(tick => { var source = Atom.Value(1); var middle = Atom.Computed(() => source.Value + 1); var target1 = Atom.Computed(() => middle.Value + 1); var target2 = Atom.Computed(() => middle.Value + 1); var run1 = Atom.AutoRun(() => target1.Get()); var run2 = Atom.AutoRun(() => target2.Get()); Assert.AreEqual(2, middle.SubscribersCount()); run1.Dispose(); tick(0); Assert.AreEqual(1, middle.SubscribersCount()); run2.Dispose(); tick(0); Assert.AreEqual(0, middle.SubscribersCount()); });
public void AutoRun() => TestZone.Run(tick => { var source = Atom.Value(0); int runs = 0; var disposer = Atom.AutoRun(() => { source.Get(); ++runs; }); Assert.AreEqual(1, runs); source.Value++; tick(0); Assert.AreEqual(2, runs); disposer.Dispose(); source.Value++; tick(0); Assert.AreEqual(2, runs); });
public void Invalidate() => TestZone.Run(tick => { // var source = Atom.Value(0); string actualization = ""; var dispose = Atom.AutoRun(() => { source.Get(); actualization += "T"; }); tick(0); Assert.AreEqual("T", actualization); source.Invalidate(); tick(0); Assert.AreEqual("TT", actualization); dispose.Dispose(); });
public void KeepAliveComputed() => TestZone.Run(tick => { var source = Atom.Value(1); var middle = Atom.Computed(() => source.Value + 1, keepAlive: true); var target = Atom.Computed(() => middle.Value + source.Value); var run = Atom.AutoRun(() => target.Get()); Assert.AreEqual(2, source.SubscribersCount()); Assert.AreEqual(1, middle.SubscribersCount()); Assert.AreEqual(1, target.SubscribersCount()); run.Dispose(); tick(0); Assert.AreEqual(1, source.SubscribersCount()); Assert.AreEqual(0, middle.SubscribersCount()); Assert.AreEqual(0, target.SubscribersCount()); middle.Deactivate(); tick(0); Assert.AreEqual(0, source.SubscribersCount()); });