Skip to content

Instantly share code, notes, and snippets.

View Clancey's full-sized avatar

James Clancey Clancey

View GitHub Profile
@Clancey
Clancey / CometMvuNoState.cs
Created February 9, 2022 21:16
Comet with pure MVU, without any state.
public class RideTheComet : View
{
public record CometRide
{
public int Rides { get; init; } = 0;
public string CometTrain => "☄️".Repeat(Rides);
}
CometRide state = new CometRide();
@Clancey
Clancey / CometPureMvu.cs
Created February 9, 2022 21:14
Comet without any INPC/Bindings
public class RideTheComet : View
{
public record CometRide
{
public int Rides { get; init; } = 0;
public string CometTrain => "☄️".Repeat(Rides);
}
State<CometRide> state = new CometRide();
@Clancey
Clancey / Reorder_Buttons.cs
Created December 17, 2021 07:10
Added re-order buttons to the images
new ScrollView(Orientation.Horizontal){
new HStack{
Enumerable.Range(0,images.Value.Count).Select(x=> new VStack{
new Image(()=> images.Value[x].Path).Frame(width:100,height:100),
new Button("Remove", ()=>{
images.Value.RemoveAt(x);
Reload();
}),
(x >0 && x < images.Value.Count - 1) ? new HStack{
new Button("<--", ()=>{
@Clancey
Clancey / imagepicker.cs
Last active December 17, 2021 06:27
Comet ImagePicker
public class MainPage : View
{
readonly State<int> ImageCount = new State<int>();
readonly State<List<(string Path, string Name)>> images = new List<(string Path, string Name)>();
Task<FileResult> currentPickerTask;
[Body]
View body()
=> new VStack {
new HStack(Comet.VerticalAlignment.Center){
@Clancey
Clancey / ArtistPlayableGroup.cs
Last active June 3, 2021 22:29
gMusic CarPlay
using System;
using System.Threading.Tasks;
using System.Linq;
namespace gMusic
{
public class ArtistPlayableGroup : PlayableGroup
{
ArtistViewModel model;
ArtistViewModel Model {get{ return model?? (model = new ArtistViewModel()); }}
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)
{
public class CounterView : View
{
readonly State<int> count = 0;
readonly State<int> step = 1;
readonly State<bool> timerOn = false;
void init()
{
count.Value = 1;
step.Value = 0;
timerOn.Value = false;
//This uses Records to make the code smaller, even though it doesnt come out until C# 9
//IT also uses a new abstract class, that shouldnt count against it's line count: https://gist.github.com/Clancey/1df421c93ee20832d793a96b30fec997
public data class Model
{
public int Count { get; set; }
public int Step { get; set; }
public bool TimerOn { get; set; }
}
public enum Msg
{
public class Testclass {
Action<bool> MyAction { get; set; }
Func<Task<bool>> MyAwaitedAction { get; set; }
public async Task AsyncTestMethod()
{
MyAction += (result) => {
Console.WriteLine(result);
};
MyAwaitedAction += () => {
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.pkg.github.com/Clancey/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="GithubNugetAccess" />
<add key="ClearTextPassword" value="a31f402ea9872240db9f947422c210177e2bb017" />
</github>