Skip to content

Instantly share code, notes, and snippets.

@mattak
Created December 21, 2016 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattak/c5327d755ebde073eab27bf842986e9c to your computer and use it in GitHub Desktop.
Save mattak/c5327d755ebde073eab27bf842986e9c to your computer and use it in GitHub Desktop.
using System.Diagnostics;
using App.Business;
using Unidux;
using UniRx;
namespace App.UI
{
public partial class Unidux : SingletonMonoBehaviour<Unidux>
{
private Store<State> _store;
private Store<State> _Store
{
get
{
if (_store == null)
{
this._store = new Store<State>(new State());
this.AssignReducers();
}
return this._store;
}
}
private Subject<State> _subject;
private Subject<State> _Subject
{
get
{
this._subject = this._subject ?? new Subject<State>();
return _subject;
}
}
public static Store<State> Store
{
get { return Instance._Store; }
}
public static State State
{
get { return Store.State; }
}
public static void Dispatch<TAction>(TAction action)
{
Store.Dispatch(action);
}
public static Subject<State> Subject
{
get { return Instance._Subject; }
}
void OnEnable()
{
this._Store.AddRenderer(UpdateSubject);
}
void OnDisable()
{
this._Store.RemoveRenderer(UpdateSubject);
}
void OnDestroy()
{
this._Subject.OnCompleted();
}
void Update()
{
this._Store.Update();
}
void UpdateSubject(State state)
{
this._Subject.OnNext(state);
}
public void InjectState(State state)
{
this._Store.InjectState(state);
this._Store.ForceStateChanged();
this._Store.ForceUpdate();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment