Comet is an MVU UIToolkit written in C#
Перейти к файлу
Jesse 33122cdfaf Fix hot reload server not launch after App run
Fix state not update UI after it added to global properties
Fix test cases build issue
2023-03-26 22:44:13 +11:00
.github/workflows Update the build scripts for main 2022-11-09 14:21:37 -09:00
.vscode Added VSCode settings 2019-12-15 18:50:41 -09:00
External Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00
art Add MVU pattern image 2020-01-22 07:53:36 +01:00
build Update Comet-Nuget.sln 2022-05-11 15:22:56 -08:00
sample Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00
src Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00
templates Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00
tests Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00
.editorconfig Remove *.md from .editorconfig 2021-09-23 17:42:05 +07: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 update maui branch 2022-10-21 10:27:58 +11:00
CODE-OF-CONDUCT.md Add CoC (#185) 2021-02-19 15:54:10 -09:00
Comet.Debug.sln Can now run without Maui Source 2022-09-29 12:07:07 -08:00
Comet.Reload.nuspec Updated the sample and template 2021-11-09 17:52:23 -09:00
Comet.Skia.nuspec Adding proper comet dependency 2020-01-17 14:09:31 -09:00
Comet.nuspec Update Comet.nuspec 2022-11-09 14:14:16 -09:00
Comet.sln Can now run without Maui Source 2022-09-29 12:07:07 -08:00
Comet.sln.DotSettings Fixed layout issue and added text alignment. 2019-09-12 16:04:32 -05:00
Directory.Build.targets Fixed net7 build 2022-11-09 14:03:53 -09:00
LICENSE Started on iOS version! 2019-06-21 13:30:03 -08:00
README.md grammar, spelling, casing 2021-12-13 21:51:53 -09:00
global.json Fix hot reload server not launch after App run 2023-03-26 22:44:13 +11:00

README.md

Comet ☄️

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

What is Comet? Comet is a modern way of writing cross-platform UIs. Based on .NET MAUI, it follows the Model View Update (MVU) pattern and magically databinds for you!

Watch this video to get a preview of the developer experience:

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 based on the MVU architecture:

MVU pattern

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

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

Or manually from your constructor:

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

Hot Reload

Using Hot Reload is the fastest way to develop your user interface.

The setup is simple and only requires a few steps:

  1. Install the Visual Studio extension Comet.Reload from Releases (or Comet for .NET Mobile if you use Visual Studio Code)
  2. Install the Comet project template available on NuGet.
  3. Add this short snippet to your AppDelegate.cs and/or MainActivity.cs, or equivalent.
#if DEBUG
Comet.Reload.Init();
#endif

See the sample projects here for examples.

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 supported?

Comet is developed on top of .NET MAUI handlers, providing its own implementation for interfaces such as Microsoft.Maui.IButton and other controls. Any platform supported by .NET MAUI can be targeted:

  • Windows
  • Android
  • iOS
  • macOS
  • Blazor

Non-MAUI application models, such as UWP or WPF, are not supported.

Disclaimer

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