question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Events aka Reactive-UI

See original GitHub issue

Add 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:76 (22 by maintainers)

github_iconTop GitHub Comments

5reactions
DianeOfTheMooncommented, Feb 23, 2018

It might be good to change the false/true to something like EventScope.Context/EventScope.Entity to help with readability.

4reactions
c0ffeeartccommented, Feb 17, 2018

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 😆

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found