laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
474 stars 48 forks source link

Add RetrieveFeature and ResolveFeature Event #110

Closed alexanderkroneis closed 2 months ago

alexanderkroneis commented 2 months ago

This PR introduces two events. RetrieveFeature is dispatched before the value is retrieved and ResolveFeature is dispatched before the feature is resolved.

A real life example. We are using Pennant to enable and disable our features conditionally based on a specific date. For example we want to enable a Chat after 1st of July. For this use case we'd like to listen to RetrieveFeature to check if it's a date-related feature and purge it on the fly.

It addresses https://github.com/laravel/pennant/issues/41.

taylorotwell commented 2 months ago

I think this should be something like RetrievingFeature and ResolvingFeature. /cc @timacdonald

timacdonald commented 2 months ago

@alexanderkroneis, could you show me how you would achieve what you want to do now that these events are present?

I have another feature for Pennant that I think might be better suited, but I wanted to make sure I understood what you were trying to do first.

alexanderkroneis commented 2 months ago

Sure. We'll add the trait PurgeFeatures to the Pennant features we'd like to purge regularly. After RetrievingFeature has been dispatched we catch it in our PurgeFeaturesListener and check if the trait exists for the given feature and if so, we check if resolve is true. If so, we purge the specific feature.

By this way we avoid to purge the feature every night even tho it's not necessary to purge it yet.

cc @timacdonald

alexanderkroneis commented 2 months ago

I renamed the events as suggested by Taylor. Let me know if there's anything I can provide to get this PR merged.

cc @timacdonald @taylorotwell

timacdonald commented 2 months ago

@alexanderkroneis, I would like to propose a different approach for the functionality you are trying to achieve.

Could you please review https://github.com/laravel/pennant/pull/111 and let me know your thoughts and if it will serve your usecase?

I'll close this one for now as I feel that it does. We can open it if it does not work for you.