Skip to content

Instantly share code, notes, and snippets.

@Clancey
Last active August 4, 2020 20:07
Show Gist options
  • Save Clancey/1df421c93ee20832d793a96b30fec997 to your computer and use it in GitHub Desktop.
Save Clancey/1df421c93ee20832d793a96b30fec997 to your computer and use it in GitHub Desktop.
public abstract class StatefulView<TMessage,TModel> : View
{
public StatefulView() { }
public StatefulView(TModel initialModel)
{
state = initialModel;
}
readonly State<TModel> state = new State<TModel>();
public void Dispatch(TMessage message)
{
var model = Update(message, state.Value);
state.Value = model;
}
[Body]
View body() => View(state.Value);
public abstract TModel Update(TMessage message, TModel model);
public abstract View View(TModel model);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment