Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Good Emitter Hygiene? #127

Open
mailok opened this issue Jan 28, 2019 · 5 comments
Open

Good Emitter Hygiene? #127

mailok opened this issue Jan 28, 2019 · 5 comments

Comments

@mailok
Copy link

mailok commented Jan 28, 2019

Hello everyone, I would like to make a proposal or a question.
Recently I saw the video Good Action Hygiene by Mike Ryan and Emitter pattern from ngxs-labs, and I would like to get what Mike Ryan talked about the actions but without the actions.

For example i have this in two different components:

Component Dashboard:

@Emitter(BurgerState.addBurguer)
public emitBurguerFromDashboard: Emittable<Burger>;

Component BurgerPage:

@Emitter(BurgerState.addBurger)
public emitBurgerFromBurgerPage: Emittable<Burger>;

but I want there to be only one implementation in the state, which in this case would be:

    @Receiver()
    public static addBurguer(ctx: StateContext<BurgerStateModel>, action: EmitterAction<Burger>) {
      // logic.....
    }

How to have all this but at the same time be able to see in my devtools:

[Dashboard] add burguer
[Burger Page] add burguer

Of course, without defining actions.

If it is not possible at this time, It would be great if I emit a payload and the source from which that payload came out, for example, something like that:

@Emitter({receiver: BurgerState.addBurguer, source: '[Dashboard] add burguer'})
public emitBurguerFromDashboard: Emittable<Burguer>;

@Emitter({receiver: BurgerState.addBurger, source: '[Burger Page] add burguer'})
public emitBurgerFromBurgerPage: Emittable<Burger>;
@splincode
Copy link
Member

@mailok
Copy link
Author

mailok commented Jan 29, 2019

@splincode But that forces me to have multiple implementations of the same logic, that does not solve what I say

@splincode
Copy link
Member

You need dynamic action type?

@mailok
Copy link
Author

mailok commented Jan 29, 2019

@splincode something like that, because otherwise I would have to do something like that in my state:

    public addBurguer(ctx: StateContext<BurgerStateModel>, action: EmitterAction<Burger>) {
      // logic.....
    }

   @Receiver({ type: '[Dashboard] add burguer' })
    public static addBurguerFromDashboard(ctx: StateContext<BurgerStateModel>, action: EmitterAction<Burger>) {
      this.addBurguer(ctx, action);
    }

   @Receiver({ type: '[Burger Page] add burguer' })
    public static addBurguerFromBurgerPage(ctx: StateContext<BurgerStateModel>, action: EmitterAction<Burger>) {
           this.addBurguer(ctx, action);
    }

@splincode
Copy link
Member

@arturovt what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants