You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For writing tests it would be very nice to have a way to collect all hooks ran by swup in an array. Could also be a nice feature to dramatically simplify the logging of hooks in debug plugin.
Describe the propsed solution 😎
I think the easiest would be to dispatch an additional CustomEvent each time swup dispatches a hook to the document:
protecteddispatchDomEvent<TextendsHookName>(hook: T,args?: HookArguments<T>): void{const detail ={ hook, args,visit: this.swup.visit};document.dispatchEvent(newCustomEvent(`swup:*`,{ detail }));// now we can listen to this!document.dispatchEvent(newCustomEvent(`swup:${hook}`,{ detail }));}
And this is how we could collect all hooks fired during a visit:
I thought about a way to do this directly, but was overwhelmed by the complexity of the hooks system. The DOM event approach seems simple and easy :)
Naming of the hook:
I thought about calling the hook "swup:all" or "swup:hook", but "swup:*" felt the most intuitive, since it makes it very clear that this is a special kind of event.
Great idea! I think we should implement this on the hook level, i.e. swup.hooks.on('*'), that way we'd still support custom dom events by extension as before.
Describe the problem 🧐
For writing tests it would be very nice to have a way to collect all hooks ran by swup in an array. Could also be a nice feature to dramatically simplify the logging of hooks in debug plugin.
Describe the propsed solution 😎
I think the easiest would be to dispatch an additional
CustomEvent
each time swup dispatches a hook to thedocument
:And this is how we could collect all hooks fired during a visit:
The output right now is:
Alternatives considered 🤔
How important is this feature to you? 🧭
Would make my life a lot easier
Checked all these? 📚
The text was updated successfully, but these errors were encountered: