GithubHelp home page GithubHelp logo

tanhuazh / comet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnet/comet

0.0 1.0 0.0 11.12 MB

Comet is an MVU UIToolkit written in C#

License: MIT License

C# 98.77% HTML 0.87% JavaScript 0.15% PowerShell 0.21%

comet's Introduction

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.

comet's People

Contributors

clancey avatar jonlipsky avatar sweekriti91 avatar twsouthwick avatar davidortinau avatar jacob-maristany avatar alexeystrakh avatar nerocui avatar matissehack avatar maxbrister avatar libin85 avatar benbtg avatar devronb avatar rogihee avatar nmilcoff avatar alexblount avatar rdavisau avatar filipoff2 avatar davidkarlas avatar davidwengier avatar denisivanitskyi avatar terrajobst avatar jeremyvignelles avatar mattleibow avatar pieeatingninjas avatar saamerm avatar spouliot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.