public void LiOpSimple() { var cd = new CompositeDisposable(); var engine = new SinglethreadEngine(); var li = engine.Li(new List <Item>()); var liValueWatcher = engine.Wa(cd, li, item => item.Value); var op1 = engine.MultiOp <Empty>(); var op2 = engine.MultiOp <Empty>(); int total = 0; engine.Computer(cd, new object[] { li, liValueWatcher }, () => { var l = li.Read(); total = 0; for (int i = 0, n = l.Count; i < n; ++i) { total += l[i].Value.Read(); } } ); engine.Computer(cd, new object[] { op1, op2 }, () => { if (op1.Read().Count > 0) { var l = li.AsWrite(); l.Add(new Item(engine, 3)); l.Add(new Item(engine, 2)); } if (op2.Read().Count > 0) { var l = li.Read(); for (int i = 0, n = l.Count; i < n; ++i) { l[i].Value.Write(l[i].Value.Read() + 1); } } } ); engine.Update(); Assert.AreEqual(0, total); op1.Fire(Empty.Instance); engine.Update(); Assert.AreEqual(5, total); op2.Fire(Empty.Instance); engine.Update(); Assert.AreEqual(7, total); cd.Dispose(); engine.Dispose(); }
public void LiWriteProxy() { var cd = new CompositeDisposable(); var engine = new SinglethreadEngine(); var li = engine.Li(new List <int> { 1, 2, 3, 4 }); int calledCount = 0; engine.Computer(cd, new object[] { li }, () => { ++calledCount; }); engine.Update(); Assert.AreEqual(1, calledCount); { var proxy = li.AsWriteProxy(); proxy.Commit(); } engine.Update(); Assert.AreEqual(1, calledCount); { var proxy = li.AsWriteProxy(); proxy.RemoveAll(_ => false); proxy.Commit(); } engine.Update(); Assert.AreEqual(1, calledCount); { var proxy = li.AsWriteProxy(); proxy.RemoveAt(0); proxy.Commit(); } engine.Update(); Assert.AreEqual(2, calledCount); Assert.AreEqual(new List <int> { 2, 3, 4 }, li.Read()); }