Skip to content

Simple, scalable state management for CSharp or Unity

License

Notifications You must be signed in to change notification settings

mooooooi/MobxForCSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MobxForCSharp

Simple, scalable state management for CSharp or Unity

Install and Update via UPM

  1. Open UPM: "Window/Package Manager"
  2. Click "+" button at the top left
  3. Select "Add package from git URL" and paste following URL: https://github.com/mooooooi/MobxForCSharp.git

Example

Prerequisite

// 1. import namespace.
using higo.mobx;

// 2. Define observable object.
public class Data : ObservableObject
{
    // 3. Define observable value.
    private ObservableValue<int> m_id;
    // 4. (Option)Make proxy for observable value.
    public int Id { get => m_id.Value; set => m_id.Value = value; }
    
    private ObservableValue<string> m_name;
    public string Name { get => m_name.Value; set => m_name.Value = value; }
    
    // 5. Implement OnBind.
    public override void OnBind()
    {
        BindValue(m_id);
        BindValue(m_name);
    }
}

Use

var data = Store.AsRoot<Data>();

data.AutoRun(() => 
{
    Console.WriteLine($"Data's reaction: Id({data.Id})");
});
// Console: Data's reaction: Id(0)

using(data.CreateActionScope())
{
    data.Id = 2;
}
// Console: Data's reaction: Id(2)

using(data.CreateActionScope())
{
    data.Name = "Changing!";
}
// Console no printing!

About

Simple, scalable state management for CSharp or Unity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages