CrabUI
|
CUICommand and CUIData is a "record (string Name, object data = null)"
You can create and dispatch them up and down the component three for whoever consumes them
This turns out to be an essential tool, it allows you to not depent on the layout
Now you don't need to pass callbacks and objects, you just know that somewhere there is a child that will consume this type of data and you just dispatch it into the void
You can rearrange the layout as you want and nothing will break
Commmands and data are essentially the same, but commands are moving up and data is moving down
To listen for commands :
To listen for data:
Also you can add callbacks to "event Action<CUICommand> OnAnyCommand" "eventAction<CUIData> OnAnyData" events to listen for anything
Commands and data will travel until someone consumes them
As you might noticed there's some asymmetry:
Commands are dispatched through a very small number of parents While data could be potentially broadcasted to a list with 10000 childs
So data broadcast is potentially laggy (although i've tested it on a list with 2000 buttons, it's balls cheap)
To address this you can add names to parent.Emits collection, then parent won't just broadcast data, it'll search for consumers and pass data only to them directly
Also note that some components will already dispatch commands if Command is defined
E.g. CUISlider will send its current value when dragged with provided command name