Events aka Reactive-UI
See original GitHub issueAdd new Attributes, Data Providers and Code Generators to generate what we know under the name Reactive UI (as explained in this Unite Talk video https://www.youtube.com/watch?v=Phx7IJ3XUzg)
[Event(false)]
public sealed class GameOverComponent : IComponent {
}
[Event(true)]
public sealed class PositionComponent : IComponent {
public Vector3 value;
}
I plan to generate 2 different events, one that’s independent from entities [Event(false)] and one that’s bound to a specific entity [Event(true)]
public interface IGameOverListener {
void OnGameOver(bool isGameOver);
}
public sealed class GameOverListenerComponent : IComponent {
public IGameOverListener value;
}
public sealed class GameOverEventSystem : ReactiveSystem<GameEntity> {
readonly IGroup<GameEntity> _listsners;
public GameOverEventSystem(Contexts contexts) : base(contexts.game) {
_listsners = contexts.game.GetGroup(GameMatcher.GameOverListener);
}
protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context) {
return context.CreateCollector(GameMatcher.GameOver.AddedOrRemoved());
}
protected override bool Filter(GameEntity entity) {
return true;
}
protected override void Execute(List<GameEntity> entities) {
foreach (var e in entities) {
foreach (var listener in _listsners) {
listener.gameOverListener.value.OnGameOver(e.isGameOver);
}
}
}
}
public interface IPositionListener {
void OnPosition(Vector3 position);
}
public sealed class PositionListenerComponent : IComponent {
public IPositionListener value;
}
public sealed class PositionEventSystem : ReactiveSystem<GameEntity> {
public PositionEventSystem(Contexts contexts) : base(contexts.game) {
}
protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context) {
return context.CreateCollector(GameMatcher.Position);
}
protected override bool Filter(GameEntity entity) {
return entity.hasPosition && entity.hasPositionListener;
}
protected override void Execute(List<GameEntity> entities) {
foreach (var e in entities) {
e.positionListener.value.OnPosition(e.position.value);
}
}
}
This is the idea, the implementation might be different once I see it in action.
Discussion and feedback is welcome
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:76 (22 by maintainers)
Top Results From Across the Web
Events
With ReactiveUI. Events all events are strongly typed. This means your IDE will help you by suggesting available events.
Read more >Events aka Reactive-UI · Issue #591 · sschmid/Entitas
I would say you always want the entity from Event(true) despite it's unique. So the generator could handle that for you. Furthermore the ......
Read more >Reactive Programming
Reactive programming is programming with asynchronous data streams. Event buses or your typical click events are really an asynchronous event stream, on which ......
Read more >Using Reactive UI in your .NET MAUI app
We will rewrite the Hello World .NET MAUI project using Reactive UI in this post. Even add a little timer, aka scheduler sample....
Read more >The Xamarin Show | Episode 17: ReactiveUI with Michael Stonis
This week, James is joined by friend of the show Michael Stonis, Xamarin MVP and Development Lead & President at Eight Bot, who...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It might be good to change the false/true to something like EventScope.Context/EventScope.Entity to help with readability.
Something like
[EntityEvent( hasContextsArg = false, hasEntityArg = enumEntityArg.CreationIndex, hasEntityFieldsArgs = true)]or[EntityEvent( argFlags = eContexts | eEntityCreationIndex | eEntityFields]. And everyone gets what he wants. Sounds like a hell of generator 😆