-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
brandonroberts
merged 9 commits into
ngrx:master
from
wesleygrimes:feature-schematic-feature-add-success-failure-effect
Jan 28, 2019
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
99bc13b
feat: add success/failure effects/actions to ng generate feature
wesleygrimes 674056f
feat: add/update unit tests for additional effects for success failure
wesleygrimes 4615abf
feat: remove added state properties, revert some of the tests back to…
wesleygrimes 7cb5bb2
feat: revert effect\index.spec.ts back to normal
wesleygrimes 9012cc3
feat: adding api flag to schematics, cleaning up tests
wesleygrimes 1a7bf87
feat: implement api flag in templates, add new tests for schematics i…
wesleygrimes 006a2bc
feat: schematics updates for api flag on features
wesleygrimes 8c059cb
feat: schematics add missing 's' to LoadFoos action type
wesleygrimes 8091938
feat: schematics add comment explaining EMTPY observable
wesleygrimes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 15 additions & 2 deletions
17
modules/schematics/src/action/files/__name@dasherize@if-flat__/__name@dasherize__.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export enum <%= classify(name) %>ActionTypes { | ||
Load<%= classify(name) %>s = '[<%= classify(name) %>] Load <%= classify(name) %>s' | ||
Load<%= classify(name) %>s = '[<%= classify(name) %>] Load <%= classify(name) %>s', | ||
<% if (api) { %>Load<%= classify(name) %>sSuccess = '[<%= classify(name) %>] Load <%= classify(name) %>s Success',<% } %> | ||
<% if (api) { %>Load<%= classify(name) %>sFailure = '[<%= classify(name) %>] Load <%= classify(name) %>s Failure',<% } %> | ||
} | ||
|
||
export class Load<%= classify(name) %>s implements Action { | ||
readonly type = <%= classify(name) %>ActionTypes.Load<%= classify(name) %>s; | ||
} | ||
<% if (api) { %> | ||
export class Load<%= classify(name) %>sSuccess implements Action { | ||
readonly type = <%= classify(name) %>ActionTypes.Load<%= classify(name) %>sSuccess; | ||
constructor(public payload: { data: any }) { } | ||
} | ||
|
||
export type <%= classify(name) %>Actions = Load<%= classify(name) %>s; | ||
export class Load<%= classify(name) %>sFailure implements Action { | ||
readonly type = <%= classify(name) %>ActionTypes.Load<%= classify(name) %>sFailure; | ||
constructor(public payload: { error: any }) { } | ||
} | ||
<% } %> | ||
<% if (api) { %>export type <%= classify(name) %>Actions = Load<%= classify(name) %>s | Load<%= classify(name) %>sSuccess | Load<%= classify(name) %>sFailure;<% } %> | ||
<% if (!api) { %>export type <%= classify(name) %>Actions = Load<%= classify(name) %>s;<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 20 additions & 2 deletions
22
modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Actions, Effect<% if (feature) { %>, ofType<% } %> } from '@ngrx/effects'; | ||
<% if (feature) { %>import { <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> | ||
<% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators';<% } %> | ||
<% if (feature && api) { %>import { EMPTY, of } from 'rxjs';<% } %> | ||
<% if (feature && api) { %>import { Load<%= classify(name) %>sFailure, Load<%= classify(name) %>sSuccess, <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> | ||
<% if (feature && !api) { %>import { <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> | ||
|
||
@Injectable() | ||
export class <%= classify(name) %>Effects { | ||
<% if (feature) { %> | ||
<% if (feature && api) { %> | ||
@Effect() | ||
load<%= classify(name) %>s$ = this.actions$.pipe( | ||
ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s), | ||
concatMap(() => | ||
EMPTY.pipe( | ||
map(data => new Load<%= classify(name) %>sSuccess({ data })), | ||
catchError(error => of(new Load<%= classify(name) %>sFailure({ error })))) | ||
) | ||
); | ||
<% } %> | ||
<% if (feature && !api) { %> | ||
@Effect() | ||
load<%= classify(name) %>s$ = this.actions$.pipe(ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s)); | ||
<% } %> | ||
<% if (feature && api) { %> | ||
constructor(private actions$: Actions<<%= classify(name) %>Actions>) {} | ||
<% } else { %> | ||
constructor(private actions$: Actions) {} | ||
<% } %> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.