Library for simple and fast design pattern that extends model, view and controller for asynchronous events in supported modern programming languages.
Use following command to install Thoaded package:
dotnet add package Thoaded
Thoaded applications are created by composing a series of simple inheritances. By convention, this components extends Modify-based Asynchronous Pattern.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Thoaded;
namespace Thoaded.Samples
{
public class SampleMoldeled : Modeled<string>
{
public override Task<string> Added(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Updated(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Deleted(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Readed(string text)
{
return Task.FromResult<string>(text);
}
public override Task<IEnumerable<string>> Queried(params string[] texts)
{
return Task.FromResult<IEnumerable<string>>(new string[0]);
}
public override Task Listened(params string[] texts)
{
return Task.FromResult<string>(string.Empty);
}
public override Task Unlistened(params string[] texts)
{
return Task.FromResult<string>(string.Empty);
}
}
public class SampleViewed : Viewed<string>
{
public override Task<string> Added(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Updated(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Deleted(string text)
{
return Task.FromResult<string>(text);
}
public override Task<string> Readed(string text)
{
return Task.FromResult<string>(text);
}
public override Task<IEnumerable<string>> Queried(params string[] texts)
{
return Task.FromResult<IEnumerable<string>>(new string[0]);
}
public override Task Listened(params string[] texts)
{
return Task.FromResult<string>(string.Empty);
}
public override Task Unlistened(params string[] texts)
{
return Task.FromResult<string>(string.Empty);
}
}
public class SampleControlled : Controlled<string>
{
// run constructor in parent class
public SampleControlled() : base(new SampleMoldeled(), new SampleViewed())
{
// dispatch read event in modeled listener
this.Modeled.Readed("Hello, World!").ContinueWith((modeled) => {
// dispatch read event to viewed listener
this.Viewed.Readed(modeled.Result).ContinueWith((viewed) => {
// print successfully
Console.WriteLine("Print " + viewed.Result + " successfully.");
});
});
}
}
}
Thoaded supports all environments that are Netstandard 2.