Multiple Process Loader Management for vanilla JavaScript.
Read the Medium post "Managing Complex Waiting Experiences on Web UIs".
DOM wait is a vanilla implementation of vue-wait.
DOM-wait helps to manage multiple loading states on the page without any conflict. It's based on a very simple idea that manages an array with multiple loading states.
- Zero-dependency. Requires nothing to work.
- No CSS. Attaches and detaches elements instead of showing and hiding them.
- Very simple API.
Add dom-wait.js to head.
<html><head><scriptsrc="dom-wait.js"></script></head><body></body></html>dom-wait is very easy to use and migrate your current projects. Assume you have some API calls ipapi.co to get client IP.
<div><h2>Your IP is:</h2><divid='ip'>#.#.#.#</div><script>var$ip=document.getElementById('ip');fetch('https://ipapi.co/json').then(response=>response.json()).then(response=>{$ip.innerHTML=response.ip;});</script></div>dom-wait watches elements with data-wait-for attribute with loading message.
<divdata-wait-for='getting ip'><h2>Your IP is:</h2><divid='ip'>#.#.#.#</div></div>This element will be attached when loading starts and detached when loading ends.
<divdata-wait-for='getting ip'><divclass='waiting'>Getting IP...</div><h2>Your IP is:</h2><divid='ip'>#.#.#.#</div></div>var$ip=document.getElementById('ip');// start waitingwait.start('getting ip');fetch('https://ipapi.co/json').then(function(response){returnresponse.json();}).then(function(response){$ip.innerHTML=response.ip;// end waitingwait.end('getting ip');});DOM-Wait doesn't make hide/show on elements. Instead, attaches and detaches elements to DOM. This makes DOM cleaner and lighter on waiting process.
<divdata-wait-for="getting ip"><!--wait:8ef4c4e7--><divid="ip">#.#.#.#</div></div>DOM-Wait detaches .waiting elements from DOM and inserts a comment node instead. When loading starts it attaches back and detaches rest of the siblings:
<divdata-wait-for="getting ip"><divclass="waiting">Loading...</div><!--wait:c9169aa9--></div>MIT © Fatih Kadir Akın
