ngrx effect throws “dispatched an invalid action: undefined”












1















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?










share|improve this question

























  • 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$ as logoutConfirmation$:Observable<Action> and see what happens ;)

    – Jota.Toledo
    Nov 22 '18 at 23:01
















1















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?










share|improve this question

























  • 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$ as logoutConfirmation$:Observable<Action> and see what happens ;)

    – Jota.Toledo
    Nov 22 '18 at 23:01














1












1








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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$ as logoutConfirmation$: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











  • 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$ as logoutConfirmation$: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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer


























  • that is correct, thank you so much man!

    – dazzed
    Nov 22 '18 at 23:13











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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this answer


























  • that is correct, thank you so much man!

    – dazzed
    Nov 22 '18 at 23:13
















1














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.






share|improve this answer


























  • that is correct, thank you so much man!

    – dazzed
    Nov 22 '18 at 23:13














1












1








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python