Created
December 21, 2016 12:45
-
-
Save mattak/c5327d755ebde073eab27bf842986e9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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