UNPKG

hyperapp-lifecycle

Version:

Small wrapper for Hyperapp and Superfine to emulate connected and disconnected lifecycle events

2 lines 1.19 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).Lifecycle={})}(this,(function(e){"use strict";let n="connected",t="disconnected";var o="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:setTimeout;function i(e){return{...e,props:{appendChild:r("appendChild",n),insertBefore:r("insertBefore",n),removeChild:r("removeChild",t),...e.props}}}function r(e,n){return function(t){return o(()=>t.dispatchEvent(new CustomEvent(n))),Object.getPrototypeOf(this)[e].apply(this,arguments)}}e.CONNECTED=n,e.DISCONNECTED=t,e.lifecycle=function(e,p=!1){const d={l:function(){return i(e.h.apply(null,arguments))}};function l(e,i,p){e.parentNode.appendChild=r("appendChild",n),e.parentNode.insertBefore=r("insertBefore",n),e.parentNode.removeChild=r("removeChild",t),p.call(),i.name===e.nodeName.toLowerCase()&&o(()=>e.dispatchEvent(new CustomEvent(n)))}return d.h=p?e.h:d.l,e.app&&(d.app=n=>l(n.node,n.view(n.init),()=>e.app.call(null,n))),e.patch&&(d.patch=(n,t)=>l(n,t,()=>e.patch.call(null,n,t))),d},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=lifecycle.js.map