initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,29 @@
|
|||
using UnityEditor.ShaderGraph;
|
||||
using ActionType = UnityEditor.ShaderGraph.IGraphDataAction;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class DataStore<T>
|
||||
{
|
||||
Action<T, ActionType> m_Reducer;
|
||||
internal T State { get; private set; }
|
||||
|
||||
public Action<T, ActionType> Subscribe;
|
||||
|
||||
internal DataStore(Action<T, ActionType> reducer, T initialState)
|
||||
{
|
||||
m_Reducer = reducer;
|
||||
State = initialState;
|
||||
}
|
||||
|
||||
public void Dispatch(ActionType action)
|
||||
{
|
||||
m_Reducer(State, action);
|
||||
// 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
|
||||
// Notifies any listeners about change in state
|
||||
Subscribe?.Invoke(State, action);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue