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

Cancelable Actions Decorator Option #191

Closed
amcdnl opened this issue Mar 28, 2018 · 14 comments
Closed

Cancelable Actions Decorator Option #191

amcdnl opened this issue Mar 28, 2018 · 14 comments
Assignees
Milestone

Comments

@amcdnl
Copy link
Member

amcdnl commented Mar 28, 2018

Add the ability to cancel previously queued actions via a API like this:

@Action(RemoveTodo, { cancelable: true })
remove() { ... }

eliminating the need for doing this:

  @Action(RemoveTodo)
  removeTodo(state: StateContext<string[]>, action: RemoveTodo) {
    return timer(5000).pipe(
      tap(() => {
        state.setState(
          state.getState().filter((_, index) => index !== action.index)
        );
      }),
      takeUntil(this.actions.pipe(ofAction(RemoveTodo)))
    );
  }

Ref: #143

@amcdnl amcdnl added this to the 2.1.0 milestone Mar 28, 2018
@amcdnl amcdnl self-assigned this Mar 28, 2018
@markwhitfeld
Copy link
Member

PS. You would probably have to support the option of "cancelable" or "cancellable" for US or UK english spelling (See here).

@amcdnl
Copy link
Member Author

amcdnl commented Mar 29, 2018

@markwhitfeld - any other thoughts? You had some interesting ideas here.

@deebloo
Copy link
Member

deebloo commented Mar 29, 2018 via email

@deebloo
Copy link
Member

deebloo commented Mar 29, 2018

see #192

@andre-davcev
Copy link

andre-davcev commented Mar 30, 2018

@amcdnl Small question here. Is there a reason we need to explicitly define whether it is cancelable? Was thinking it might be simpler to have it implicit.

@amcdnl
Copy link
Member Author

amcdnl commented Mar 31, 2018

@greycloak - u only want this for typeaheads, saves should always happen.

@markwhitfeld
Copy link
Member

Just to add to the mix, I think that the option name of 'cancelable' is maybe a bit ambiguous regarding its impact and behavior. Maybe @greycloak was asking about it because it was unclear...?
To make it more user friendly there could be another setting name that would be better suited.
Here are some options of names from the top of my head:
cancelsPrevious, cancelPrevious, latestCallOverrides, latestCallWins, latestCallCancelsPrevious

In my opinon the cancelsPrevious is clean and to the point, and when I did a search about the differences between SwitchMap, MergeMap and ConcatMap, the SwitchMap was described as it cancels the previous observable, as would be implied explicitly by this setting name.

One subtle issue I have with the cancelable setting name is that this is US spelling and it would be cancellable as UK spelling (as mentioned previously). This would be sure to cause confusion with framework users.

My vote is for cancelsPrevious. Thoughts? Suggestions? @deebloo @amcdnl

PS. I think we would also have to create a preservesOrder setting to represent the equivalent of ConcatMap at some stage.

@andre-davcev
Copy link

@amcdnl @markwhitfeld We have an action that will kick off a chain of other actions depending on the success of the previous. My assumption was that we need to use a switchMap to cancel the current action. And then we can just subscribe to the original dispatch and will be notified when it finishes the whole chain or fails along the way. The problem is that we see two emits on the first success action and 4 emits on the 2nd. My thought was that this enhancement for 2.1 was related to that. Or it's also possible we're just using ngxs or rxjs wrong.

@amcdnl
Copy link
Member Author

amcdnl commented Apr 2, 2018

Implemented in 2.1.0-beta.0 using takeLast name.

@amcdnl amcdnl closed this as completed Apr 2, 2018
@markwhitfeld
Copy link
Member

Hi @amcdnl and @deebloo
I was wondering about the reasoning behind the option name of takeLast?
I find it a bit unintuitive because the takeLast rxjs operator will only apply once the observable completes. In our case the action stream never completes, so it means that we are creating a meaning for this that it outside its original meaning. Are we happy with this?
If I saw the option being used in code I wouldn't know what it meant until I read the docs.

Is it still possible to review the option name?

@amcdnl
Copy link
Member Author

amcdnl commented Apr 2, 2018

@deebloo - he liked that one, i'm indifferent.

@markwhitfeld
Copy link
Member

@deebloo I looked at your doc comment where you describe the takeLast option. You describe it as follows:
* Cancel the previous uncompleted request(s).
Do you think we could change the name to be closer to the description?
ie. cancelPrevious, cancelUncompleted, cancelPreviousUncompleted

I think I prefer cancelUncompleted.
I'm happy to chat on gitter. Ping me when you are available.

@deebloo
Copy link
Member

deebloo commented Apr 3, 2018

will do. I personally wanted it to be called "cancelPrevious". The inline comment should also be updated since it is canceling previous observables not necessarily previous requests.

@andre-davcev
Copy link

@amcdnl Whatever it is you changed, you fixed our observable emit permutations issue. Thanks! Awesome library. Boilerplate hell no more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants