Skip to content

Instantly share code, notes, and snippets.

@aspnetde
Created February 10, 2020 15:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspnetde/9f0283bc895e8f2d963399ab63a314af to your computer and use it in GitHub Desktop.
Save aspnetde/9f0283bc895e8f2d963399ab63a314af to your computer and use it in GitHub Desktop.
namespace MvuCsharp
{
public class Cmd
{
public static readonly Cmd None = new Cmd();
public static Cmd OfMsg(IMessage msg) => new Cmd(); // TODO
}
}
using System;
namespace MvuCsharp
{
public class Model
{
public int Count { get; }
public Model(int count)
{
Count = count;
}
}
public interface IMessage
{
}
public class Increment : IMessage
{
public int Value { get; }
public Increment(int value)
{
Value = value;
}
}
public class IncrementRandom : IMessage
{
}
public class CmdIncrementRandom : IMessage
{
}
public static class DemoProgram
{
private static readonly Random _random = new Random();
private static Increment IncrementRandom() => new Increment(_random.Next(10, 100));
public static ValueTuple<Model, Cmd> Init() => (new Model(0), Cmd.None);
public static ValueTuple<Model, Cmd> Update(IMessage msg, Model model)
{
return msg switch
{
Increment increment => (new Model(increment.Value), Cmd.None),
IncrementRandom _ => (model, Cmd.OfMsg(new CmdIncrementRandom())),
CmdIncrementRandom _ => (model, Cmd.OfMsg(IncrementRandom())),
_ => throw new NotImplementedException()
};
}
public static void View()
{
// TODO
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment