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
I was just reading the code a bit for fun and I believe preInit is broken. I could be mistaken. I've not tested it.
exportdefault(ctx)=>{// Callback function to execute when mutations are observedconstcallback=(mutations,observer)=>{mutations.forEach((mutation)=>{// Check if "inputField" added to the DOMif(ctx.input){// If yes disconnect the observerobserver.disconnect();// Initialize autoComplete.jsctx.init();}});};// Create mutation observer instanceconstobserver=newMutationObserver(callback);// Start observing the entire DOM until "inputField" is present// The entire document will be observed for all changesobserver.observe(document,{childList: true,subtree: true});};
if (ctx.input) will always fail, won't it? This is more like the code you want
exportdefault(ctx)=>{// Callback function to execute when mutations are observedconstcallback=(mutations,observer)=>{mutations.forEach((mutation)=>{if(mutation.type==="childList"){for(letnodeofmutation.addedNodes){if(node.nodeType===1&&node.tagName==="INPUT"){// XXX Also check that it matches ctx.options.selectorobserver.disconnect()ctx.init()}}}});};// Create mutation observer instanceconstobserver=newMutationObserver(callback);// Start observing the entire DOM until "inputField" is present// The entire document will be observed for all changesobserver.observe(document,{childList: true,subtree: true});};
I am probably misunderstanding preInit and observe completely.
The text was updated successfully, but these errors were encountered:
It looks broken the way it is currently, and your code is the correct implementation of the observe functionality which is meant to watch for the input field until it's added to the DOM.
Would you like to pull a PR for this one, or should I take care of it?
mutations.forEach((mutation) => { must be changed to for (const mutation of mutations) so that you can break out of the loop when you find an element that matches.
After ctx.init() just do return, probably.
And of course implement the XXX comment (I use XXX to mark things that must be changed/fixed before release.)
I was just reading the code a bit for fun and I believe
preInit
is broken. I could be mistaken. I've not tested it.if (ctx.input)
will always fail, won't it? This is more like the code you wantI am probably misunderstanding
preInit
andobserve
completely.The text was updated successfully, but these errors were encountered: