Skip to content

an alternative to Redux in C# without writing actions nor reducers by leveraging LiteDB.Realtime

License

Notifications You must be signed in to change notification settings

FuturistiCoder/LiteDB.StateStore

Repository files navigation

LiteDB.StateStore

Build Status

Get started

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

// a helper which can collect all your subscriptions
var subscriptions = new SubscriptionManager();
using (var db = new RealtimeLiteDatabase(new MemoryStream()))
{
    // subscribe to username
    subscriptions += db.StateStore<string>("username").Subscribe(username =>
        Dispatcher.BeginInvokeOnMainThread(() =>
        {
            userLabel.Text = username;
        }));

    db.StateStore<string>("username").Set("FuturistiCoder");
    // userLabel.Text will be 'FuturistiCoder';
}

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).

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

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

About

an alternative to Redux in C# without writing actions nor reducers by leveraging LiteDB.Realtime

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages