Skip to content

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

Merged
brandonroberts merged 9 commits into
ngrx:masterfrom
wesleygrimes:feature-schematic-feature-add-success-failure-effect
Jan 28, 2019
Merged

feat(Schematics): add success/failure effects/actions to ng generate feature#1530
brandonroberts merged 9 commits into
ngrx:masterfrom
wesleygrimes:feature-schematic-feature-add-success-failure-effect

Conversation

@wesleygrimes

@wesleygrimes wesleygrimes commented Jan 25, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@ngrxbot

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@coveralls

coveralls commented Jan 25, 2019

Copy link
Copy Markdown

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

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@wesleygrimes

Copy link
Copy Markdown
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
Copy Markdown
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

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@wesleygrimes

wesleygrimes commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

@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

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@ngrxbot

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@wesleygrimes

Copy link
Copy Markdown
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

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@wesleygrimes

wesleygrimes commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

@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

ngrxbot commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

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

@ngrxbot

ngrxbot commented Jan 28, 2019

Copy link
Copy Markdown
Collaborator

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

@ngrxbot

ngrxbot commented Jan 28, 2019

Copy link
Copy Markdown
Collaborator

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

@timdeschryver timdeschryver left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

ngrxbot commented Jan 28, 2019

Copy link
Copy Markdown
Collaborator

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

@brandonroberts

Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

Schematics: add common success/failure actions to feature schematic Effects generated by Schematics cause 100% CPU / Frozen tab

5 participants