A game about forced loneliness, made by TACStudios
1using UnityEditor.ShaderGraph;
2using ActionType = UnityEditor.ShaderGraph.IGraphDataAction;
3using System;
4using UnityEngine;
5
6namespace UnityEditor.ShaderGraph
7{
8 class DataStore<T>
9 {
10 Action<T, ActionType> m_Reducer;
11 internal T State { get; private set; }
12
13 public Action<T, ActionType> Subscribe;
14
15 internal DataStore(Action<T, ActionType> reducer, T initialState)
16 {
17 m_Reducer = reducer;
18 State = initialState;
19 }
20
21 public void Dispatch(ActionType action)
22 {
23 m_Reducer(State, action);
24 // Note: This would only work with reference types, as value types would require creating a new copy, this works given that we use GraphData which is a heap object
25 // Notifies any listeners about change in state
26 Subscribe?.Invoke(State, action);
27 }
28 }
29}