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
In framework usages, when a hook is registered (.hook()) after being called .callHook with no handlers, callers will lose the opportunity to catch it:
// A: It will be called when reaching Bhooks.hook('myplugin',()=>{/* is called */})// B: Calls any hooks for `myplugin` are already registedawaithooks.callHook('myplugin','foo','bar')// C: Will only by called by subsequent myplugin calls. Missing (B)hooks.hook('myplugin',()=>{/* never called */})
To solve this issue, we need to kinda record the hook calls and replay them when new hook is registered but this means we need to keep them in memory. Simply solution would be defining an initialization phase to set bookable into a recording state and make it replay immediately (C).
// A: Gets called on line (B)hooks.hook('myplugin',()=>{/* gets called */})// Record calls while initializing frameworkconstcallDifferedHooks=hooks.differ()// B: Calls hook from (A) also internally stores a call to ['myplugin, 'foo', 'bar']awaithooks.callHook('myplugin','foo','bar')// C: normally won't be called for call in (B)hooks.hook('myplugin',()=>{/* gets called */})// Call hook registered in (C) from recordings// Stop recording and cleanup memoryawaitcallDifferedHooks()
Alternatives:
We could instead have hooks.record() / hooks.stop()
While I find it simpler, it is also less explicit and encouraging to handle within a scope. differHooks can later accept a prefix as well for multi phased recording of specific hooks rather than all.
We immediately call hook in line (C) opon registration
It makes hooks called faster but also because it is in background, error handling harder for consumer (internally, best we could throw a console error)
We could have hooks.setup(() => { }) that runs callback for auto record any reply afterwards.
This could be based on the implementation above. Might work for simple cases, might make code uglier. Have to try.
Alternative syntax with setup:
// Calling to setup, starts recording callsconstpromise=hooks.setup(async()=>{// A: Gets called on line (B)hooks.hook('myplugin',()=>{/* gets called */})// B: Calls hook from (A) also internally stores a call to ['myplugin, 'foo', 'bar']awaithooks.callHook('myplugin','foo','bar')// C: normally won't be called for call in (B)hooks.hook('myplugin',()=>{/* gets called */})})// Call hook registered in (C) from recordings// Stop recording and cleanup memoryawaitpromise
The text was updated successfully, but these errors were encountered:
In framework usages, when a hook is registered (
.hook()
) after being called.callHook
with no handlers, callers will lose the opportunity to catch it:To solve this issue, we need to kinda record the hook calls and replay them when new hook is registered but this means we need to keep them in memory. Simply solution would be defining an initialization phase to set bookable into a recording state and make it replay immediately (
C
).Alternatives:
hooks.record()
/hooks.stop()
differHooks
can later accept a prefix as well for multi phased recording of specific hooks rather than all.hooks.setup(() => { })
that runs callback for auto record any reply afterwards.Alternative syntax with setup:
The text was updated successfully, but these errors were encountered: