https://github.com/liangxiegame/uiwidgetsreduxpersist
Saver Middle Ware 4 UIWidgets Redux
https://github.com/liangxiegame/uiwidgetsreduxpersist
u3d uiwidgets unity unity3d
Last synced: 6 months ago
JSON representation
Saver Middle Ware 4 UIWidgets Redux
- Host: GitHub
- URL: https://github.com/liangxiegame/uiwidgetsreduxpersist
- Owner: liangxiegame
- License: mit
- Created: 2019-05-16T05:08:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-16T05:33:49.000Z (over 6 years ago)
- Last Synced: 2025-02-13T21:19:02.200Z (8 months ago)
- Topics: u3d, uiwidgets, unity, unity3d
- Language: C#
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIWidgetsReduxPersist
Saver Middle Ware 4 UIWidgets Redux### Example:
``` csharp
using System.Collections.Generic;
using Unity.UIWidgets;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.Redux;
using Unity.UIWidgets.widgets;
// 1.import namespace
using QFramework.UIWidgets.ReduxPersist;namespace QF.UIWidgets.ReduxPersist.Example
{
// 2.declare state
class ExampleState : AbstractPersistState
{
public int Count = 0;
}public class Example : UIWidgetsPanel
{
protected override Widget createWidget()
{
var store = new Store((state, action) =>
{
switch (action)
{
case IncreaseCountAction _:
return new ExampleState
{
Count = state.Count + 1
};case DecreaseCountAction _:
return new ExampleState
{
Count = state.Count - 1
};
}return state;
},
// 3.call load
ExampleState.Load(),
// 4.add middleware
ReduxPersistMiddleware.create());
return new StoreProvider(store,
child: new StoreConnector(
converter: state => state.Count,
builder: (context, model, dispatcher) =>
{
return new Row(
children: new List()
{
new FlatButton(
child: new Text("-"),
onPressed: () => { dispatcher.dispatch(new DecreaseCountAction()); }
),
new Text(model.ToString()),
new FlatButton(
child: new Text("+"),
onPressed: () => { dispatcher.dispatch(new IncreaseCountAction()); }
),
}
);
}
)
);
}
}class IncreaseCountAction
{}
class DecreaseCountAction
{}
}```
### Dependenciy:
* [JSON.NET for Unity](https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347)
* [UIWidgets](https://github.com/UnityTech/UIWidgets)