lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

Conditional runs #173

Closed Wulfheart closed 2 years ago

Wulfheart commented 2 years ago

I just stumbled across this and thought it would be a good idea to make running an action as an object analogous to running it as a job.

Therefore I propose to add runIf(bool, ...) and runUnless(bool, ...) (similar to dispatch) to the AsObject syntax so something like this isn't necessary anymore:

if($someCondition){
    Action::run();
}

// would become this
Action::runIf($someCondition);
lorisleiva commented 2 years ago

I like this! 👌

Do you think we can get away with a minor semver update for it? Technically it is a breaking change as we're adding methods to a trait but I doubt this will have an real impact on devs. Wdyt?

Wulfheart commented 2 years ago

I don't think that it is a major breaking change. As per semver.org:

  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.

Therefore I think it is only a minor version as it only adds functionality in a backward compatible manner. I am going to open a PR for it.

lorisleiva commented 2 years ago

Thanks! I meant more like, if someone has already defined the runIf or runUnless methods and the signatures don't match then it will break their actions but the likelihood of that is very low so I'm happy with a minor jump. 🙂

lorisleiva commented 2 years ago

Released in v2.4.0! 🔥