demigor / nreact

React for C#/Xaml
MIT License
63 stars 5 forks source link

in React (for JS) there are the so called "props"... how do Props in NReact work? #4

Open danielkornev opened 7 years ago

demigor commented 7 years ago

NClass has property bags keyed by NProperty class to store properties and state. To access these information, use Get/GetState/Set/SetState methods with corresponding NProperty.

NProperty defines specifics of the application (setter) of this property for different target (Xaml) types. Basic NProperty instances for Xaml library are automatically generated by corresponding reflection-based code generator (see NProps.generated.*.cs) and packed into NReact.NFactory.Properties read-only singleton instance.

Custom properties with additional names could be defined in custom singleton instance. If one wants to provide support for additional classes in existing NProperty, just call its configuration method like Property{T}, List{T} etc.

Currently I define props manually as public C# properties with Get/Set:

using static NReact.NFactory; // to refer Properties singleton without NFactory class name.

...

public string[] Items
{ 
  get { return Get(Properties.Items, default(string[])); } 
  set { Set(Properties.Items, value); } 
}

and state variables as protected C# properties with GetState/SetState:

protected DateTime Start 
{
  get { return GetState(Properties.Start, default(DateTime)); } 
  set { SetState(Properties.Start, value); } 
}
protected DateTime Now 
{
  get { return GetState(Properties.Now, default(DateTime)); } 
  set { SetState(Properties.Now, value); } 
}

The plan is to generate someday this code automatically from something more simple like this:

public string[] Items { get; set; }
protected DateTime Start { get; set; }
protected DateTime Now { get; set; }