Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UniduxIntroduction

mattak
July 23, 2016

 UniduxIntroduction

2016-07-23 Unibook & LT conference.

mattak

July 23, 2016
Tweet

More Decks by mattak

Other Decks in Programming

Transcript

  1. "DUJPO$SFBUPS 26 public class CountDispatcher : MonoBehaviour
 {
 public CountAction

    ActionType = CountAction.Increment;
 
 void Start()
 {
 var button = this.GetComponent<Button>();
 button.onClick.AddListener(() => Unidux.Instance.Store.Dispatch(ActionType));
 }
 }
  2. 3FEVDFS 27 public static class CountReducer
 {
 public static State

    Reduce(State state, CountAction action)
 {
 switch (action)
 {
 case CountAction.Increment:
 state.Count++;
 break;
 case CountAction.Decrement:
 state.Count--;
 break;
 }
 
 return state;
 }
 }
  3. 3FOEFSFS 28 public class CountRenderer : MonoBehaviour
 {
 void OnEnable()


    {
 var store = Unidux.Instance.Store;
 this.AddDisableTo(store, Render);
 Render(store.State);
 }
 
 void Render(State state)
 {
 var text = this.GetComponent<Text>();
 text.text = state.Count.ToString();
 }
 }
  4. 6OJEVYDT 29 public class Unidux : SingletonMonoBehaviour<Unidux>
 {
 private Store<State>

    _store;
 public Store<State> Store
 {
 get
 {
 if (null == _store)
 {
 _store = new Store<State>(new State());
 _store.AddReducer<CountAction>(CountReducer.Reduce);
 }
 return _store;
 }
 }
 
 void Update()
 {
 this.Store.Update();
 }
 }
  5. 32 特徴 - クラス間が疎結合になる (メンテ, テスト容易に) - 記述ルールが統⼀される - 状態がStateに集約される

    (記録、デバック容易に) - イベントサイクルが⼀⽅向 (可読性アップ) デメリット - 単純なものの記述量が少し増える - 短期書きなぐり系には冗⻑ (ゲームジャムとか)