ngrx effect throws “dispatched an invalid action: undefined”
I have this effect for logout confirmation under the condition of a dialog response, but am getting the following errors:
ERROR Error: Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: undefined
and
ERROR TypeError: Actions must be objects
heres the effect:
@Effect()
logoutConfirmation$ = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
map(action => {
if (action.confirmationDialog) {
this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => {
if (confirmed) {
return new LogoutConfirmed();
} else {
return new LogoutCancelled();
}
})
);
} else {
return new LogoutConfirmed();
}
})
);
it works when confirmation dialog is activated, I guess it's something wrong with the map of the dialog's response, have been trying to understand it but couldn't fin a way.
Any one has a clue on this?
angular ngrx ngrx-effects
add a comment |
I have this effect for logout confirmation under the condition of a dialog response, but am getting the following errors:
ERROR Error: Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: undefined
and
ERROR TypeError: Actions must be objects
heres the effect:
@Effect()
logoutConfirmation$ = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
map(action => {
if (action.confirmationDialog) {
this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => {
if (confirmed) {
return new LogoutConfirmed();
} else {
return new LogoutCancelled();
}
})
);
} else {
return new LogoutConfirmed();
}
})
);
it works when confirmation dialog is activated, I guess it's something wrong with the map of the dialog's response, have been trying to understand it but couldn't fin a way.
Any one has a clue on this?
angular ngrx ngrx-effects
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
Try addingreturn this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
Declare the explicit type oflogoutConfirmation$
aslogoutConfirmation$:Observable<Action>
and see what happens ;)
– Jota.Toledo
Nov 22 '18 at 23:01
add a comment |
I have this effect for logout confirmation under the condition of a dialog response, but am getting the following errors:
ERROR Error: Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: undefined
and
ERROR TypeError: Actions must be objects
heres the effect:
@Effect()
logoutConfirmation$ = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
map(action => {
if (action.confirmationDialog) {
this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => {
if (confirmed) {
return new LogoutConfirmed();
} else {
return new LogoutCancelled();
}
})
);
} else {
return new LogoutConfirmed();
}
})
);
it works when confirmation dialog is activated, I guess it's something wrong with the map of the dialog's response, have been trying to understand it but couldn't fin a way.
Any one has a clue on this?
angular ngrx ngrx-effects
I have this effect for logout confirmation under the condition of a dialog response, but am getting the following errors:
ERROR Error: Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: undefined
and
ERROR TypeError: Actions must be objects
heres the effect:
@Effect()
logoutConfirmation$ = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
map(action => {
if (action.confirmationDialog) {
this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => {
if (confirmed) {
return new LogoutConfirmed();
} else {
return new LogoutCancelled();
}
})
);
} else {
return new LogoutConfirmed();
}
})
);
it works when confirmation dialog is activated, I guess it's something wrong with the map of the dialog's response, have been trying to understand it but couldn't fin a way.
Any one has a clue on this?
angular ngrx ngrx-effects
angular ngrx ngrx-effects
edited Nov 22 '18 at 23:10
Jota.Toledo
9,60562248
9,60562248
asked Nov 22 '18 at 21:47
dazzeddazzed
7319
7319
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
Try addingreturn this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
Declare the explicit type oflogoutConfirmation$
aslogoutConfirmation$:Observable<Action>
and see what happens ;)
– Jota.Toledo
Nov 22 '18 at 23:01
add a comment |
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
Try addingreturn this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
Declare the explicit type oflogoutConfirmation$
aslogoutConfirmation$:Observable<Action>
and see what happens ;)
– Jota.Toledo
Nov 22 '18 at 23:01
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
Try adding
return this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
Try adding
return this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
Declare the explicit type of
logoutConfirmation$
as logoutConfirmation$:Observable<Action>
and see what happens ;)– Jota.Toledo
Nov 22 '18 at 23:01
Declare the explicit type of
logoutConfirmation$
as logoutConfirmation$:Observable<Action>
and see what happens ;)– Jota.Toledo
Nov 22 '18 at 23:01
add a comment |
1 Answer
1
active
oldest
votes
Your outer map should be a mergeMap
, as you are mapping the action to a new stream (in case that the condition is true).
You can fix this as follows:
import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';
@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);
As a side note, always declare the explicit type of your effects in order to get errors at compile instead of run time.
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438332%2fngrx-effect-throws-dispatched-an-invalid-action-undefined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your outer map should be a mergeMap
, as you are mapping the action to a new stream (in case that the condition is true).
You can fix this as follows:
import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';
@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);
As a side note, always declare the explicit type of your effects in order to get errors at compile instead of run time.
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
add a comment |
Your outer map should be a mergeMap
, as you are mapping the action to a new stream (in case that the condition is true).
You can fix this as follows:
import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';
@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);
As a side note, always declare the explicit type of your effects in order to get errors at compile instead of run time.
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
add a comment |
Your outer map should be a mergeMap
, as you are mapping the action to a new stream (in case that the condition is true).
You can fix this as follows:
import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';
@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);
As a side note, always declare the explicit type of your effects in order to get errors at compile instead of run time.
Your outer map should be a mergeMap
, as you are mapping the action to a new stream (in case that the condition is true).
You can fix this as follows:
import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';
@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);
As a side note, always declare the explicit type of your effects in order to get errors at compile instead of run time.
edited Nov 22 '18 at 23:14
answered Nov 22 '18 at 23:09
Jota.ToledoJota.Toledo
9,60562248
9,60562248
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
add a comment |
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
that is correct, thank you so much man!
– dazzed
Nov 22 '18 at 23:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438332%2fngrx-effect-throws-dispatched-an-invalid-action-undefined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is it a runtime or compiletime error ?
– Korte
Nov 22 '18 at 22:21
no, it's when the action is dispatched.
– dazzed
Nov 22 '18 at 22:25
Try adding
return this.dialogService //etc...
– Korte
Nov 22 '18 at 22:30
got Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: [object Object] and Actions must have a type property
– dazzed
Nov 22 '18 at 22:37
Declare the explicit type of
logoutConfirmation$
aslogoutConfirmation$:Observable<Action>
and see what happens ;)– Jota.Toledo
Nov 22 '18 at 23:01