Open carlgieringer opened 3 years ago
Hmm, first of all: I think it's fine to pass along the old value to the callback, that shouldn't be a problem and can be handy.
But secondly, your example looks fairly complex (especially requiresReload = requiresReload || requestReload && (isTruthy(prevCookie) || cookie.accepted)
), and I would personally strife for an atomic function that would be able to respond to the new state regardless of what the old state was.
That would simplify your script I think.
For example, maybe just write a sentryInit
function that does nothing when already initialized.
I am responding to cookieConsent.on('update') calls to modify my app's state to match the user's current preferences. E.g., if they enable ERROR_REPORTING, I can initialize sentry.
I found this difficult because in order to take the correct actions, I need to know if the cookie value is actually changing or not. Below I have some example code from a React app. My workaround is to persist the cookie state in a Redux store so that I am able to compare new values to old values.
I wanted to get initial feedback on this feature. Is there any apparent reason that it wouldn't be a good idea or would be difficult based upon the library's current implementation? Thanks!