项目作者: FuturistiCoder

项目描述 :
an alternative to Redux in C# without writing actions nor reducers by leveraging LiteDB.Realtime
高级语言: C#
项目地址: git://github.com/FuturistiCoder/LiteDB.StateStore.git
创建时间: 2020-02-29T09:45:24Z
项目社区:https://github.com/FuturistiCoder/LiteDB.StateStore

开源协议:MIT License

下载


LiteDB.StateStore

Build Status

Get started

You can get, set or even subscribe a KeyValue state without writing actions nor reducers.

  1. // a helper which can collect all your subscriptions
  2. var subscriptions = new SubscriptionManager();
  3. using (var db = new RealtimeLiteDatabase(new MemoryStream()))
  4. {
  5. // subscribe to username
  6. subscriptions += db.StateStore<string>("username").Subscribe(username =>
  7. Dispatcher.BeginInvokeOnMainThread(() =>
  8. {
  9. userLabel.Text = username;
  10. }));
  11. db.StateStore<string>("username").Set("FuturistiCoder");
  12. // userLabel.Text will be 'FuturistiCoder';
  13. }

StateStore<T> : the T can be reference type or value type. But if you want to save and listen collections, use db.Realtime.Collection<T> instead (LiteDB.Realtime).

  1. subscriptions += db.Realtime.Collection<TodoItem>("TodoItems").Subscribe(items =>
  2. Dispatcher.BeginInvokeOnMainThread(() =>
  3. {
  4. listView.ItemsSource = items;
  5. })
  6. // listView will be updated after TodoItems changed
  7. );

Call subscriptions.Dispose()will dispose all your added subscriptions.