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

feat(effects): allow non-dispatching effects to not return an action #1689

Merged
merged 7 commits into from
Apr 9, 2019

Conversation

timdeschryver
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Follow up to #1667

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 2, 2019

Preview docs changes for ead9718 at https://previews.ngrx.io/pr1689-ead9718/

@@ -4,14 +4,14 @@ import { EffectMetadata } from './models';

const CREATE_EFFECT_METADATA_KEY = '__@ngrx/effects_create__';

export function createEffect<T extends Action>(
source: (() => Observable<T>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have quite a few overloads, I think we can get away with just 3:

export function createEffect<
  R extends Observable<unknown> | ((...args: any[]) => Observable<unknown>)
>(source: () => R, options: { dispatch: false }): R;
export function createEffect<
  T extends Action,
  R extends Observable<T> | ((...args: any[]) => Observable<T>)
>(source: () => R, options?: { dispatch: true }): R;
export function createEffect<
  T extends Action,
  R extends Observable<T> | ((...args: any[]) => Observable<T>)
>(source: () => R, { dispatch = true } = {}): R {
  const effect = source();
  Object.defineProperty(effect, CREATE_EFFECT_METADATA_KEY, {
    value: {
      dispatch
    },
  });
  return effect;
}


expect(effect['__@ngrx/effects_create__']).toEqual({ dispatch: false });
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test with expectSnippet to catch that createEffect(() => of('foo')) /is not assignable to type 'Observable/ ?
I think it could be beneficial - right not nothing prevents from accidentally adjusting the code to return Observable<any>

@timdeschryver
Copy link
Member Author

I'll address @alex-okrushko 's feedback

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 4, 2019

Preview docs changes for ccf611e at https://previews.ngrx.io/pr1689-ccf611e/

@brandonroberts
Copy link
Member

@timdeschryver changes LGTM, but its failing in CI with the snippet checker.

@timdeschryver
Copy link
Member Author

Yep thanks, I couldn't figure out why the CI is failing yesterday. I'll take a second look with a fresh mind later today.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 5, 2019

Preview docs changes for 0013159 at https://previews.ngrx.io/pr1689-0013159/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 5, 2019

Preview docs changes for de12acb at https://previews.ngrx.io/pr1689-de12acb/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 6, 2019

Preview docs changes for d4b7d79 at https://previews.ngrx.io/pr1689-d4b7d79/

1 similar comment
@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 6, 2019

Preview docs changes for d4b7d79 at https://previews.ngrx.io/pr1689-d4b7d79/

@timdeschryver timdeschryver force-pushed the pr/effect-no-dispatch branch from d4b7d79 to 121b6c2 Compare April 6, 2019 12:32
@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 6, 2019

Preview docs changes for 121b6c2 at https://previews.ngrx.io/pr1689-121b6c2/

1 similar comment
@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 6, 2019

Preview docs changes for 121b6c2 at https://previews.ngrx.io/pr1689-121b6c2/

@timdeschryver
Copy link
Member Author

Seems like I'm not able to solve the bazel tests 😅

@brandonroberts
Copy link
Member

I'll take a look

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 9, 2019

Preview docs changes for 88da3a2 at https://previews.ngrx.io/pr1689-88da3a2/

@brandonroberts brandonroberts merged commit 04e07a6 into master Apr 9, 2019
@brandonroberts brandonroberts deleted the pr/effect-no-dispatch branch April 9, 2019 20:28
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

Successfully merging this pull request may close these issues.

4 participants