mean-expert-official / fire-starter

Starter kit for the fireloop.io platform
MIT License
16 stars 8 forks source link

Feat: Pass optional param with all actions #1

Open JonnyBGod opened 7 years ago

JonnyBGod commented 7 years ago

This would provide an easy way to pass extra data for action extensibility.

Good example would be for an Alert reducer, enabling us to pass "success/fail" messages to be consumed by Alert Effects/Reducers.

This would work for other use cases if we keep optional param as open as possible.

JonnyBGod commented 7 years ago

Major refactor though, will have to do it next week.

brannon-darby commented 7 years ago

@JonnyBGod - if you can provide more details, i'll be happy to add this. i don't have much experience with ngrx though, so i may need some guidance.

JonnyBGod commented 7 years ago

I will try to update the ngrx implementation next week.

Did a few changes since this first version.

JonnyBGod commented 7 years ago

but for reference related to this issue it should be changed to something like this:

actions:

  actions.create = class implements Action {
    public readonly type = actionTypes['CREATE'];

    constructor(public payload: any, **public meta?: any**) { }
  };

effects:

  protected create: Observable<LoopbackAction> = this.actions$
    .ofType(this.actionTypes.CREATE)
    .mergeMap((action: LoopbackAction) =>
      this.apiService.create(action.payload)
        .map((response) => new this.actions.createSuccess(response, **action.meta**))
        .catch((error) => concat(
          of(new this.actions.createFail(error, **action.meta**)),
          of(new LoopbackErrorActions.error(error, **action.meta**))
        ))
    );

without the ** of course.

JonnyBGod commented 7 years ago

Another refactor should be the reducers helper methods.

https://github.com/mean-expert-official/fireloop-starter/blob/develop/webapp/src/app/shared/sdk/reducers/auth.ts#L67-L85

should change to

export const getLoopbackAuthState = (state: any) => state.loopbackAuth;
export const getLoopbackAuthToken = (state: any) => state.loopbackAuth;
export const getLoopbackAuthUser = (state: any) => state.loopbackAuth.user;
export const getLoopbackAuthUserId = (state: any) => state.loopbackAuth.userId;

and similar with other reducers.

beeman commented 7 years ago

@JonnyBGod good to hear you can spend some time on this soon. I hope to get this puppy out asap.

Let's hop on a call when you have time so we can iron out the things and talk through the steps we need to take to finalize.

JonnyBGod commented 7 years ago

also still related to this issue, for the meta parameter to validate with TS we have to add the following to BaseModels.ts

export interface LoopbackAction extends Action {
  meta?: any;
}
JonnyBGod commented 7 years ago

@beeman Yes, sure will get back to you for the call hopefully mid next week.

Sorry for almost two months of absence here but been busy. But I see you got a few extra hand on it 👍

beeman commented 7 years ago

Yeah the starter is doing great with help from @brannon-darby and @kattsushi. We aim to release a beta version once the ngrx stuff lands in the sdk-builder alpha/beta