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(Schematics): add success/failure effects/actions to ng generate feature #1530

Merged
merged 9 commits into from
Jan 28, 2019
Merged

feat(Schematics): add success/failure effects/actions to ng generate feature #1530

merged 9 commits into from
Jan 28, 2019

Conversation

wesleygrimes
Copy link
Contributor

@wesleygrimes wesleygrimes commented Jan 25, 2019

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?

Closes #1529
Should resolve #1524

What is the new behavior?

The PR enhances the default effect generated for feature.

  • Adds 2 new actions: LoadFeatureSuccess and LoadFeatureFailure
  • Enhances feature state interface and initialState with data, loading and error properties the
  • Enhances feature reducer adding switch cases for each action type
    • LoadFeature action sets loading to true
    • LoadFeatureSuccess action sets loading to false, nulls error property and updates data with payload.
    • LoadFeatureFailure action sets loading to false, populates error from payload
  • Enhances default loadFeatureEffect$ to demonstrate the idea of a request action, and then based on the return of an observable dispatch a success or failure action.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@wesleygrimes
Copy link
Contributor Author

I'm updating the unit tests on this schematic to match the new code

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 99bc13b at https://previews.ngrx.io/pr1530-99bc13b/

@coveralls
Copy link

coveralls commented Jan 25, 2019

Coverage Status

Coverage increased (+0.2%) to 88.977% when pulling 8091938 on wesleygrimes:feature-schematic-feature-add-success-failure-effect into d6cc83c on ngrx:master.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 674056f at https://previews.ngrx.io/pr1530-674056f/

@wesleygrimes
Copy link
Contributor Author

Looks like the bazel build step failed but it was a timeout issue:

#!/bin/bash -eo pipefail
yarn
yarn install v1.10.1
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
Too long with no output (exceeded 10m0s)

@brandonroberts
Copy link
Member

We'll investigate if it keeps timing out. Some initial feedback:

  • This should be behind an option for a feature (--api maybe??), so its opt-in at least for 7.x.
  • The current tests should remain as-is, with new tests for verifying it works as intended.
  • We don't want to make any assumptions on state structure, but provide actions and default returns for the reducers.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 674056f at https://previews.ngrx.io/pr1530-674056f/

@wesleygrimes
Copy link
Contributor Author

wesleygrimes commented Jan 25, 2019

@brandonroberts

We'll investigate if it keeps timing out. Some initial feedback:

  • This should be behind an option for a feature (--api maybe??), so its opt-in at least for 7.x.
  • The current tests should remain as-is, with new tests for verifying it works as intended.
  • We don't want to make any assumptions on state structure, but provide actions and default returns for the reducers.

That all sounds good to me. Just one question regarding tests....

How should I handle a current test that is going to fail now because the import { } from line it's checking has changed to include the new Success and Failure actions? Also the test checking that the effect added is correct will fail now because the effect contents have changed.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 4615abf at https://previews.ngrx.io/pr1530-4615abf/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 7cb5bb2 at https://previews.ngrx.io/pr1530-7cb5bb2/

@wesleygrimes
Copy link
Contributor Author

@brandonroberts regarding tests, nevermind, I get what you're saying, I will create new tests that test the schematics with the new flag enabled. The current tests will be reverted to match exactly as before as they are testing with the flag disabled by default.

Sorry for the confusion.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 9012cc3 at https://previews.ngrx.io/pr1530-9012cc3/

@wesleygrimes
Copy link
Contributor Author

wesleygrimes commented Jan 25, 2019

@brandonroberts latest commit includes...

  • New flagged added named api we can change this if needed.
  • Existing tests have been left untouched
  • Created new tests that tests schematics with the api flag enabled.
  • Templates have been updated to utilize the new api flag and only define and implement the success and failure actions if the api flag is true.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 25, 2019

Preview docs changes for 1a7bf87 at https://previews.ngrx.io/pr1530-1a7bf87/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 28, 2019

Preview docs changes for 006a2bc at https://previews.ngrx.io/pr1530-006a2bc/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 28, 2019

Preview docs changes for 8c059cb at https://previews.ngrx.io/pr1530-8c059cb/

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

LGTM 👍

load<%= classify(name) %>s$ = this.actions$.pipe(
ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s),
concatMap(() =>
EMPTY.pipe(
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we need some comment here to tell the user to replace the empty observable?

Suggested change
EMPTY.pipe(
/** An EMPTY observable only emits completion. Replace with your own observable API request */
EMPTY.pipe(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 28, 2019

Preview docs changes for 8091938 at https://previews.ngrx.io/pr1530-8091938/

@brandonroberts
Copy link
Member

LGTM. Docs for https://ngrx.io/guide/schematics/feature can be done separately.

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