Comet is an MVU UIToolkit written in C#
Перейти к файлу
James Clancey bfafd1c4c4 Added back net standard 2.0 2021-07-26 10:14:24 -08:00
.github/workflows Fixed the main build 2021-07-14 13:04:16 -08:00
.vscode Added VSCode settings 2019-12-15 18:50:41 -09:00
External Update Maui 2021-07-14 11:45:42 -08:00
art Add MVU pattern image 2020-01-22 07:53:36 +01:00
build Merge branch 'dev' into main 2021-07-13 18:27:02 -08:00
sample Merge branch 'dev' into main 2021-07-13 18:27:02 -08:00
src Added back net standard 2.0 2021-07-26 10:14:24 -08:00
templates Updated the template 2021-07-22 10:03:55 -08:00
tests Fixed the tests 2021-07-13 16:10:13 -08:00
.editorconfig Disable Resharper wrap long lines in editorconfig and test format Aligment layout (#169) 2020-01-28 22:10:47 -09:00
.gitattributes Added GitAttributes 2019-07-15 23:24:50 -08:00
.gitignore Fixed 2 way bindings!!!! 2019-08-07 11:29:11 -04:00
.gitmodules Switched to dotnet/Maui repo 2021-04-06 14:32:11 -08:00
CODE-OF-CONDUCT.md Add CoC (#185) 2021-02-19 15:54:10 -09:00
Comet-net6.sln Net6 now uses maui workload. And hopefully builds Windows 2021-07-09 14:54:47 -08:00
Comet.Blazor.sln Blazor Code formatting 2019-12-13 10:04:23 -09:00
Comet.Skia.nuspec Adding proper comet dependency 2020-01-17 14:09:31 -09:00
Comet.WinUI.sln Windows now builds properly. Sample still needs updating 2021-07-12 19:25:57 -08:00
Comet.nuspec Added back net standard 2.0 2021-07-26 10:14:24 -08:00
Comet.sln started in net6 stuff again 2021-04-14 16:00:11 -08:00
Comet.sln.DotSettings Fixed layout issue and added text alignment. 2019-09-12 16:04:32 -05:00
Directory.Build.props Update Directory.Build.props 2021-07-13 09:30:06 -08:00
Directory.Build.targets Revert "Delete Directory.Build.targets" 2021-07-14 10:49:24 -08:00
LICENSE Started on iOS version! 2019-06-21 13:30:03 -08:00
NuGet.config brought back the nuget.config 2021-06-17 23:37:31 -08:00
README.md Update nuspec and readme 2021-06-02 19:09:29 -08:00

README.md

Comet ☄️

dev-build Clancey.Comet on fuget.org Chat on Discord

What is Comet? Comet is a prototype for a new UI Framework/Pattern to write app UI. It follows the Model View Update (MVU) pattern. It magically databinds for you!

Video Preview:

Video Demo

Getting Started

When you're ready to take a ride on the comet, head over to the wiki and follow the Getting Started guide.

Key Concepts

Comet is an MVU style pattern:

MVU pattern

View is a screen. Views have a Body method that you can assign either by an attribute [Body]:

public class MyPage : View {
	[Body]
	View body () => new Text("Hello World");
}

or:

public class MyPage : View {
	public MyPage() {
		Body = body;
	}
	View body () => new Text("Hello World");
}

Hot Reload

Hot Reload is included by default! The setup is very easy: a Visual Studio extension and a NuGet. Download both from Releases here on GitHub.

Download and install the VS extension from the Releases

Then add to your AppDelegate.cs and/or MainActivity.cs, or similar. See the sample projects here for examples.

 #if DEBUG
            Comet.Reload.Init();
 #endif

State

As of right now there are two supported ways to add state.

1. Simple data types like int, bool?

Just add a State<T> field to your View

class MyPage : View {
	readonly State<int> clickCount = 1;
}

View is state aware. When the state changes, databinding will automatically update, or rebuild the view as needed.

2. Do you want to use more complex data types?

You can either implement INotifyPropertyRead or you can use BindingObject to make it even simpler.

Add it as a Field/Property, and add the [State] attribute!

public class MainPage : View {
		class MyBindingObject : BindingObject {
			public bool CanEdit {
				get => GetProperty<bool> ();
				set => SetProperty (value);
			}
			public string Text {
				get => GetProperty<string> ();
				set => SetProperty (value);
			}
		}

		[State]
		readonly MyBindingObject state;
}

INotifyPropertyRead is just like INotifyPropertyChanged. Just call PropertyRead whenever a property Getter is called. And PropertyChanged whenever a property Value changes.

How do I use the State?

Simply update the stateful value and the framework handles the rest.

public class MyPage : View {

	readonly State<int> clickCount = 1;
	readonly State<string> text = "Hello World";

	public MyPage() {
		Body = () => new VStack {
			new Text (text),			
			new Button("Update Text", () => state.Text = $"Click Count: {clickCount.Value++}")
		};

	}
}

That is all!, now when the Text Changes everything updates.

What if I want to format my value without an extra state property?

While new Button("Update Text", () => state.Text = $"Click Count: {clickCount.Value++}" ) works, it isn't efficient.

Instead, use new Text(()=> $"Click Count: {clickCount}").

public class MyPage : View {

	readonly State<int> clickCount = new State<int> (1);

	public MyPage() {
		Body = () => new VStack {
			new Text (() => $"Click Count: {clickCount}"),
			new Button("Update Text", () => {
				clickCount.Value++;
			}
		};
	}
}

What platforms are being targeted?

  • iOS
  • Android
  • UWP
  • WPF
  • Mac OS
  • Xamarin.Forms - all Forms targets: Linux, macOS, Tizen, WPF, and of course Android, iOS, UWP.
  • Blazor

Disclaimer

Comet is a proof of concept. There is no official support. Use at your own Risk.