Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active March 29, 2017 11:06
Show Gist options
  • Save Maarten88/f4baf41db31c47ee155ed46292191a51 to your computer and use it in GitHub Desktop.
Save Maarten88/f4baf41db31c47ee155ed46292191a51 to your computer and use it in GitHub Desktop.
// Defined separately from the grain, this reducer can be taken out and shared with
// a Xamarin / XAML app using Redux.NET as the clientside store
public static CounterState Reducer(CounterState state, IAction action)
{
switch (action)
{
case IncrementCounterAction a:
return new CounterState(state) { Count = (state?.Count ?? 0) + 1 };
case DecrementCounterAction a:
return new CounterState(state) { Count = (state?.Count ?? 0) - 1 };
case StartCounterAction a:
return new CounterState(state) { Started = true };
case StopCounterAction a:
return new CounterState(state) { Started = false };
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment