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(store): create action stream that shows the action lifecycle #255

Merged
merged 8 commits into from Apr 10, 2018

Conversation

deebloo
Copy link
Member

@deebloo deebloo commented Apr 10, 2018

No description provided.

@deebloo deebloo requested a review from amcdnl April 10, 2018 02:00
@markwhitfeld
Copy link
Member

markwhitfeld commented Apr 10, 2018

I assume that the @Action handlers will only respond to dispatched actions? We may need to look for a syntax for response to completion in future. Something like:

@Action(Completed(FeedAnimals))

or

@Action(onCompletion(FeedAnimals))

or

@ActionCompleted(FeedAnimals)

@deebloo
Copy link
Member Author

deebloo commented Apr 10, 2018

Hmmmm. Not sure if we wanna do that or not. Could potentially also be another config option.

@deebloo
Copy link
Member Author

deebloo commented Apr 10, 2018

Whatever we decide I think it will have to wait till after this based on the way our current dispatch works

Copy link
Member

@amcdnl amcdnl left a comment

Choose a reason for hiding this comment

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

Looks good overall, had some minor comments and found an issue unrelated to this PR.


* `ofAction`: triggers both when an action has been dispatched and when it completes
* `ofActionDispatched`: triggers when an action has been dispatched but NOT when it completes
* `ofActionCompleted`: triggers when an action has been completed but NOT when it is dispatched
Copy link
Member

Choose a reason for hiding this comment

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

We might want a ofActionErrored too. Just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ill look into it

@@ -117,7 +117,7 @@ export class StateFactory {
if (result instanceof Observable) {
result = result.pipe(
(<ActionOptions>actionMeta.options).cancelUncompleted
? takeUntil(actions$.pipe(ofAction(action.constructor)))
? takeUntil(actions$.pipe(ofActionDispatched(action.constructor)))
Copy link
Member

Choose a reason for hiding this comment

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

is action here the class or instance? It looks like instance and if so, this will cause issues if the action dispatched is not a class (think devtools or websocket). We probably need to change the action.constructor to check and return.

Copy link
Member Author

Choose a reason for hiding this comment

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

it is counting on an instance yes. we can make this more robust but we should also be safer in the operators as well

Copy link
Member Author

Choose a reason for hiding this comment

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

actually I should probably put all of that logic in the operators anyway

@SkipSelf()
parent: StateStream
) {
constructor() {
Copy link
Member

Choose a reason for hiding this comment

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

If we remove all that, do we event need the constructor now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think something breaks if there is no immediate value

.pipe(map(() => this._stateStream.getValue()));
.pipe(
tap(() => {
this._actions.next({ action, status: ActionStatus.Completed });
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about making these class and just say: new CompletedAction(action)?

Copy link
Member Author

@deebloo deebloo Apr 10, 2018

Choose a reason for hiding this comment

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

This would actually add more boilerplate since we would have to create a new class for each type we create

return filter((ctx: ActionContext) => {
const actionType = getActionTypeFromInstance(ctx.action);

if (status) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer:

const type =  allowedTypes[actionType] ;
return status ? type && ctx.status === status || type;

* `ofAction`: triggers both when an action has been dispatched and when it completes
* `ofActionDispatched`: triggers when an action has been dispatched but NOT when it completes
* `ofActionCompleted`: triggers when an action has been completed but NOT when it is dispatched

Copy link
Member

Choose a reason for hiding this comment

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

Need to add this to the changelog too.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

@amcdnl
Copy link
Member

amcdnl commented Apr 10, 2018

@markwhitfeld listening via decorators would be super cool but not possible due to AoT and needing to unbind on destroy. see this for more info: https://medium.com/thecodecampus-knowledge/the-easiest-way-to-unsubscribe-from-observables-in-angular-5abde80a5ae3

@deebloo
Copy link
Member Author

deebloo commented Apr 10, 2018

@amcdnl I don't think AOT has anything to do with this in particular. I think we could investigate but would def be a separate issue

@deebloo deebloo merged commit 0d1e6e7 into master Apr 10, 2018
@amcdnl amcdnl deleted the stream-the-things branch April 10, 2018 14:37
@xmlking
Copy link
Contributor

xmlking commented Apr 11, 2018

ofActionErrored is not exposed. should ofActionComplete be ofActionCompleted ?

import { Actions, ofAction, ofActionComplete, ofActionDispatched } from '@ngxs/store';
import { ofActionErrored } from '@ngxs/store/src/of-action';

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.

None yet

4 participants