本文整理汇总了C#中Cell.Sample方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.Sample方法的具体用法?C# Cell.Sample怎么用?C# Cell.Sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cell
的用法示例。
在下文中一共展示了Cell.Sample方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SLabel
public SLabel(Cell<string> text)
{
Action<string> setText = t => this.Dispatcher.InvokeIfNecessary(() => this.Text = t);
// Set the initial value at the end of the transaction so it works with CellLoops.
Transaction.Post(() => setText(text.Sample()));
// ReSharper disable once UseObjectOrCollectionInitializer
List<IListener> listeners = new List<IListener>();
listeners.Add(Operational.Updates(text).Listen(setText));
this.listeners = listeners;
}
示例2: SButton
public SButton(Cell<bool> enabled)
{
StreamSink<Unit> sClickedSink = new StreamSink<Unit>();
this.SClicked = sClickedSink;
this.Click += (sender, args) => sClickedSink.Send(Unit.Value);
// Set the initial value at the end of the transaction so it works with CellLoops.
Transaction.Post(() => this.IsEnabled = enabled.Sample());
// ReSharper disable once UseObjectOrCollectionInitializer
List<IListener> listeners = new List<IListener>();
listeners.Add(Operational.Updates(enabled).Listen(e => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = e)));
this.listeners = listeners;
}
示例3: STextBox
public STextBox(Stream<string> setText, string initText, Cell<bool> enabled)
{
base.Text = initText;
List<IListener> listeners = new List<IListener>();
StreamSink<int> sDecrement = new StreamSink<int>();
Cell<bool> allow = setText.Map(_ => 1).OrElse(sDecrement).Accum(0, (b, d) => b + d).Map(b => b == 0);
StreamSink<string> sUserChanges = new StreamSink<string>();
this.SUserChanges = sUserChanges;
this.Text = sUserChanges.Gate(allow).OrElse(setText).Hold(initText);
TextChangedEventHandler textChangedEventHandler = (sender, args) =>
{
string text = base.Text;
this.Dispatcher.InvokeAsync(() => sUserChanges.Send(text));
};
this.TextChanged += textChangedEventHandler;
// Set the initial value at the end of the transaction so it works with CellLoops.
Transaction.Post(() => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = enabled.Sample()));
listeners.Add(setText.Listen(t =>
{
this.Dispatcher.InvokeAsync(() =>
{
this.TextChanged -= textChangedEventHandler;
base.Text = t;
this.TextChanged += textChangedEventHandler;
sDecrement.Send(-1);
});
}));
listeners.Add(Operational.Updates(enabled).Listen(e => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = e)));
this.disposeListeners = () =>
{
foreach (IListener l in listeners)
{
using (l)
{
}
}
};
}
示例4: Integrate
public static Cell<Signal> Integrate(Cell<Signal> sig, double initial)
{
Stream<Signal> sSig = Operational.Updates(sig);
return sSig.Accum(sig.Sample().Integrate(initial), (n, o) => n.Integrate(o.ValueAt(n.T0)));
}