-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
plugin.js
1 lines (1 loc) · 1.1 KB
/
plugin.js
1
!function(){function t(t){let e=t.substr(t.search(/[A-Z]/));return e[0].toLowerCase()+e.substr(1)}function e(t,e){let r=t.indexOf(e);-1!==r&&t.splice(r,1)}kontra.plugin={register(e,r){const n=kontra[e].prototype||kontra[e];n._inc||(n._inc={},n._bInc=function(t,e,...r){return this._inc[e].before.reduce((e,r)=>{let n=r(t,...e);return n||e},r)},n._aInc=function(t,e,r,...n){return this._inc[e].after.reduce((e,r)=>{let o=r(t,e,...n);return o||e},r)}),Object.getOwnPropertyNames(r).forEach(e=>{let o=t(e);n[o]&&(n["_o"+o]||(n["_o"+o]=n[o],n[o]=function(...t){let e=this._bInc(this,o,...t),r=n["_o"+o].call(this,...e);return this._aInc(this,o,r,...t)}),n._inc[o]||(n._inc[o]={before:[],after:[]}),e.startsWith("before")?n._inc[o].before.push(r[e]):e.startsWith("after")&&n._inc[o].after.push(r[e]))})},unregister(r,n){const o=kontra[r].prototype||kontra[r];o._inc&&Object.getOwnPropertyNames(n).forEach(r=>{let c=t(r);r.startsWith("before")?e(o._inc[c].before,n[r]):r.startsWith("after")&&e(o._inc[c].after,n[r])})},extend(t,e){const r=kontra[t].prototype||kontra[t];Object.getOwnPropertyNames(e).forEach(t=>{r[t]||(r[t]=e[t])})}}}();