store icon indicating copy to clipboard operation
store copied to clipboard

🚀[FEATURE]: Add option to specify Lifecycle Point to @Action() decorator

Open rweng opened this issue 7 years ago • 5 comments

It would be handy to do s.th. like this:

class MyState {
  @Action(SyncDatabase)
  syncDatabase(ctx){ ctx.patchState({isSyncing: true}) }

  @Action(SyncDatabase, {on: 'SUCCESSFUL'})
  onSyncDone(ctx, action) { ctx.patchState({isSyncing: false}) }
}

I am not sure how exactly the API should look like, or whether it would also be useful to add another lifecycle hook for completed. Also, it would be handy to have to result of the Promise / Observable on the action.

I know it is possible to subscribe to the action stream and do this manually and this is just syntactic sugar. However, I feel like this would be a nice addition since for me it is more readable than having subscriptions on the action stream while at the same time reducing Action definitions (e.g. a separate SyncDatabaseDone).

What do you think?

rweng avatar Jul 11 '18 04:07 rweng

I like this idea and have thought about it a few times. We could look at options over the api because I think there are a few ways to go here. @amcdnl what do you think?

markwhitfeld avatar Jul 11 '18 05:07 markwhitfeld

I like this! Lets blow out the API ideas!

amcdnl avatar Jul 15 '18 19:07 amcdnl

Just throwing out some question coming in my mind:

What are the lifecycle events we want/ when are they called? When did an action succeed? And what happens when we have to handlers one failing, one succeeding?

Is there a way to pass data along from one handler to another? (I guess the action object should be immutable)

juliusstoerrle avatar Jul 16 '18 18:07 juliusstoerrle

For the API, how about functions similar to the operators for the Action stream:

@Action(dispatched([FeedAnimals]))
//... 

@Action(cancelled([FeedAnimals]))
//... 

@Action(errored([FeedDucks, FeedPigs]))
//... 

@Action(successful([FeedAnimals]))
//... 

What do you think?

markwhitfeld avatar Jul 17 '18 18:07 markwhitfeld

I might be delusional but wouldn't this also help fix the issue #139?

filipjnc avatar Jul 28 '18 21:07 filipjnc