-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable load callbacks #414
Conversation
buble complains too much
feat: add skip option
feat: disconnect mutation observer once DOM has loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far. Only 2 small things
Codecov Report
@@ Coverage Diff @@
## master #414 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 31 33 +2
Lines 449 511 +62
Branches 127 145 +18
=====================================
+ Hits 449 511 +62
Continue to review full report at Codecov.
|
destructuring doesnt work in ie9
dont rely on mutationobserver
Due to issues in IE9, I've opted for a more basic approach. Its quite ugly if you ask me, but adding the onload attribute on ssr makes sure that we know the element has been loaded also when the loading takes place before we can add a load event listener. I've also removed the MutationObserver and just try to add callbacks on every document.readyState change. Have to fix the tests again once you approve. |
* __vm_l: set by onload attribute, whether the element was loaded | ||
* __vm_ev: whether the event listener was added or not | ||
*/ | ||
if (element.__vm_cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've could have made this an object like __vm = {}
instead but as __vm_l
needs to be set from the onload attribute and using an object there is too complicated, this approach of separate variables seemed ok to me.
Resolves: #240
This pr adds the possibility for adding callbacks which are called when eg the script has been loaded. This makes it possible to chain scripts which are depending on each other.
Client side implementation
When the element is created the onload attribute is just directly set
Server side implementation
${tagIDKeyName}
set (vmid
/hid
)onload="this.__vm_l=1"
${ssrAttribute}
attributetagIDKeyName
VueMeta uses the following three props directly on the element for hydration/ load callback control:
__vm_cb
whether the load callback has been called__vm_l
set by onload attribute, whether the element was loaded__vm_ev
whether the event listener was added or notskip
attributeI have added a
skip
attribute for tag definitions in metaInfo so its easier to do reactive chaining (see async-callback example)Potential caveats
Callbacks on tags which are loaded before the main app will probably not triggernot anymore due to onload attribute which is always addedToDo