Allow list for "when" parameter
Closed this issue · 2 comments
rsinger86 commented
In my projects, it's been a little cumbersome to stack decorators when you want to react to multiple fields changing:
@hook("after_update", when="published", has_changed=True)
@hook("after_update", when="path", has_changed=True)
@hook("after_update", when="type", has_changed=True)
def handle_update(self):
# do something
I see a couple of ways to handle this:
Option 1:
@hook("after_update", when=["type", "path", "published"], has_changed=True)
def handle_update(self):
# do something
Option 2:
@hook("after_update", when_any=["type", "path", "published"], has_changed=True)
def handle_update(self):
# do something
Option 2 would enable adding a when_all
parameter later on if we want to get a little fancy with boolean logic. On the other hand, maybe it's best to keep this simple - nothing wrong with stacking decorators. Any feedback would be appreciated.
simkimsia commented
I vote for when_any
rsinger86 commented
@simkimsia - this is in the latest release. Thanks for your input!