diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a3a15..d9f5743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ 更新日志 +## [1.4.1](https://github.com/1977474741/spa-custom-hooks/compare/v1.4.0...v1.4.1) (2023-12-08) + + +### Performance Improvements + +* 优化钩子触发逻辑 ([6fa493c](https://github.com/1977474741/spa-custom-hooks/commit/6fa493c711777124d899b0a9404780a87dd93b45)) + # [1.4.0](https://github.com/1977474741/spa-custom-hooks/compare/v1.3.0...v1.4.0) (2023-12-06) diff --git a/lib/spa-custom-hooks.js b/lib/spa-custom-hooks.js index dd63845..3f77685 100644 --- a/lib/spa-custom-hooks.js +++ b/lib/spa-custom-hooks.js @@ -1 +1 @@ -"use strict";function t(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,n)}return o}function e(e){for(var o=1;ot.length)&&(e=t.length);for(var o=0,n=new Array(e);o1||-1!=o.indexOf(e[0])?e:[]}},{key:"splitHook",value:function(t){var e=this;t=t.replace("on",""),this.presetHooksName.sort((function(t,e){return e.length-t.length}));var o=new RegExp("("+this.presetHooksName.join("|")+")","g");return t.split(o).filter((function(t){return e.hook[t]}))}}]),t}(),H={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=H["vue-miniprogram"],A=function(t,n,i,r){function c(t,e,o){if(this.customHook){var n=this.customHook.hook,i=Object.keys(n).find((function(t){return n[t].name===o}));if(!n[i].hit)return void h.call(this,e,o)}u.call(this,e,"component",t,o)}function u(t,e,o,n){if(!this.customHook){var a=m(this,j.hooksKey);if(j.isPage(a)){!i.state&&r&&(i.state=this[r]||r);var c="component"===e;Object.defineProperty(this,"customHook",{value:new b({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:n}),configurable:!0,enumerable:!1})}}}function s(t){return t.reduce((function(t,e){return(t[e]=function(t){h.call(this,t,e)})&&t}),{})}function h(t,e){if(("object"==o(this.customHook)||null==o(this.customHook))&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var n=this.customHook.hook,i=["beforeDestroy","destroyed","onUnload"].includes(e);for(var r in n){var a=n[r];a.name==e?a.cycleStart():a.destroy==e&&a.cycleEnd(),i&&a.unwatchFn&&a.unwatchFn()}i&&delete this.customHook}}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=H[t.userAgentKey]),l=i,y=n,t.mixin(e(e({},s(v)),{},a({},j.initHook,(function(t){u.call(this,t,"page",void 0,j.initHook)})),"miniprogram"===j.name?a(a(a(a(a(a({},j.initHookApp,(function(t){u.call(this,t,"app",void 0,j.initHookApp)})),j.initHookComponentWx,(function(t,e){u.call(this,e,"component",t,j.initHookComponentWx)})),j.initHookComponentAlipayInit,(function(t,e){u.call(this,e,"component",t,j.initHookComponentAlipayInit)})),j.initHookComponentAlipay,(function(t,e){c.call(this,t,e,j.initHookComponentAlipay)})),"lifetimes",e(e({},s(k)),{},a({},j.initHookComponentLifetimes,(function(t,e){c.call(this,t,e,j.initHookComponentLifetimes)})))),"pageLifetimes",e({},s(g))):{}))},O=Object.freeze({__proto__:null,get BASE(){return j},install:A}),S={mixin:function(t){var e=this,o=App,n=Page,i=Component;App=function(n){e.mergeHook(t,n),o(n)},Page=function(o){e.mergeHook(t,o),n(o)},Component=function(o){e.mergeComponentHook(t,o);var n=e.mixinLifetimes(t,o);i(n)}},mergeHook:function(t,e){for(var o=function(){var t=c(i[n],2),o=t[0],r=t[1],a=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;o=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(c)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=c(o.value,2),n=t[0],i=t[1],r=e[n];e[n]=function(){for(var t=arguments.length,o=new Array(t),n=0;nt.length)&&(e=t.length);for(var o=0,n=new Array(e);o1||-1!=o.indexOf(e[0])?e:[]}},{key:"splitHook",value:function(t){var e=this;t=t.replace("on",""),this.presetHooksName.sort((function(t,e){return e.length-t.length}));var o=new RegExp("("+this.presetHooksName.join("|")+")","g");return t.split(o).filter((function(t){return e.hook[t]}))}}]),t}(),H={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=H["vue-miniprogram"],A=function(t,n,i,r){function c(t,e,o){this.customHook?h.call(this,e,o):u.call(this,e,"component",t,o)}function u(t,e,o,n){if(!this.customHook){var a=m(this,j.hooksKey);if(j.isPage(a)){!i.state&&r&&(i.state=this[r]||r);var c="component"===e;Object.defineProperty(this,"customHook",{value:new b({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:n}),configurable:!0,enumerable:!1})}}}function s(t){return t.reduce((function(t,e){return(t[e]=function(t){h.call(this,t,e)})&&t}),{})}function h(t,e){if(("object"==o(this.customHook)||null==o(this.customHook))&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var n=this.customHook.hook,i=["beforeDestroy","destroyed","onUnload","didUnmount","detached"].includes(e);for(var r in n){var a,c=n[r];c.name==e?c.cycleStart():c.destroy==e&&c.cycleEnd(),i&&(null===(a=c.unwatchFn)||void 0===a||a.call(c))}i&&delete this.customHook}}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=H[t.userAgentKey]),l=i,y=n,t.mixin(e(e({},s(v)),{},a({},j.initHook,(function(t){u.call(this,t,"page",void 0,j.initHook)})),"miniprogram"===j.name?a(a(a(a(a(a({},j.initHookApp,(function(t){u.call(this,t,"app",void 0,j.initHookApp)})),j.initHookComponentWx,(function(t,e){u.call(this,e,"component",t,j.initHookComponentWx)})),j.initHookComponentAlipayInit,(function(t,e){u.call(this,e,"component",t,j.initHookComponentAlipayInit)})),j.initHookComponentAlipay,(function(t,e){c.call(this,t,e,j.initHookComponentAlipay)})),"lifetimes",e(e({},s(k)),{},a({},j.initHookComponentLifetimes,(function(t,e){c.call(this,t,e,j.initHookComponentLifetimes)})))),"pageLifetimes",e({},s(g))):{}))},O=Object.freeze({__proto__:null,get BASE(){return j},install:A}),S={mixin:function(t){var e=this,o=App,n=Page,i=Component;App=function(n){e.mergeHook(t,n),o(n)},Page=function(o){e.mergeHook(t,o),n(o)},Component=function(o){e.mergeComponentHook(t,o);var n=e.mixinLifetimes(t,o);i(n)}},mergeHook:function(t,e){for(var o=function(){var t=c(i[n],2),o=t[0],r=t[1],a=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;o=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(c)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=c(o.value,2),n=t[0],i=t[1],r=e[n];e[n]=function(){for(var t=arguments.length,o=new Array(t),n=0;nt.length)&&(e=t.length);for(var o=0,n=new Array(e);o1||-1!=o.indexOf(e[0])?e:[]}},{key:"splitHook",value:function(t){var e=this;t=t.replace("on",""),this.presetHooksName.sort((function(t,e){return e.length-t.length}));var o=new RegExp("("+this.presetHooksName.join("|")+")","g");return t.split(o).filter((function(t){return e.hook[t]}))}}]),t}(),H={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=H["vue-miniprogram"],A=function(t,n,i,r){function c(t,e,o){if(this.customHook){var n=this.customHook.hook,i=Object.keys(n).find((function(t){return n[t].name===o}));if(!n[i].hit)return void h.call(this,e,o)}u.call(this,e,"component",t,o)}function u(t,e,o,n){if(!this.customHook){var a=m(this,j.hooksKey);if(j.isPage(a)){!i.state&&r&&(i.state=this[r]||r);var c="component"===e;Object.defineProperty(this,"customHook",{value:new b({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:n}),configurable:!0,enumerable:!1})}}}function s(t){return t.reduce((function(t,e){return(t[e]=function(t){h.call(this,t,e)})&&t}),{})}function h(t,e){if(("object"==o(this.customHook)||null==o(this.customHook))&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var n=this.customHook.hook,i=["beforeDestroy","destroyed","onUnload"].includes(e);for(var r in n){var a=n[r];a.name==e?a.cycleStart():a.destroy==e&&a.cycleEnd(),i&&a.unwatchFn&&a.unwatchFn()}i&&delete this.customHook}}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=H[t.userAgentKey]),l=i,y=n,t.mixin(e(e({},s(v)),{},a({},j.initHook,(function(t){u.call(this,t,"page",void 0,j.initHook)})),"miniprogram"===j.name?a(a(a(a(a(a({},j.initHookApp,(function(t){u.call(this,t,"app",void 0,j.initHookApp)})),j.initHookComponentWx,(function(t,e){u.call(this,e,"component",t,j.initHookComponentWx)})),j.initHookComponentAlipayInit,(function(t,e){u.call(this,e,"component",t,j.initHookComponentAlipayInit)})),j.initHookComponentAlipay,(function(t,e){c.call(this,t,e,j.initHookComponentAlipay)})),"lifetimes",e(e({},s(k)),{},a({},j.initHookComponentLifetimes,(function(t,e){c.call(this,t,e,j.initHookComponentLifetimes)})))),"pageLifetimes",e({},s(g))):{}))},O=Object.freeze({__proto__:null,get BASE(){return j},install:A}),S={mixin:function(t){var e=this,o=App,n=Page,i=Component;App=function(n){e.mergeHook(t,n),o(n)},Page=function(o){e.mergeHook(t,o),n(o)},Component=function(o){e.mergeComponentHook(t,o);var n=e.mixinLifetimes(t,o);i(n)}},mergeHook:function(t,e){for(var o=function(){var t=c(i[n],2),o=t[0],r=t[1],a=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;o=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(c)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=c(o.value,2),n=t[0],i=t[1],r=e[n];e[n]=function(){for(var t=arguments.length,o=new Array(t),n=0;nt.length)&&(e=t.length);for(var o=0,n=new Array(e);o1||-1!=o.indexOf(e[0])?e:[]}},{key:"splitHook",value:function(t){var e=this;t=t.replace("on",""),this.presetHooksName.sort((function(t,e){return e.length-t.length}));var o=new RegExp("("+this.presetHooksName.join("|")+")","g");return t.split(o).filter((function(t){return e.hook[t]}))}}]),t}(),H={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage:function(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=H["vue-miniprogram"],A=function(t,n,i,r){function c(t,e,o){this.customHook?h.call(this,e,o):u.call(this,e,"component",t,o)}function u(t,e,o,n){if(!this.customHook){var a=m(this,j.hooksKey);if(j.isPage(a)){!i.state&&r&&(i.state=this[r]||r);var c="component"===e;Object.defineProperty(this,"customHook",{value:new b({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:n}),configurable:!0,enumerable:!1})}}}function s(t){return t.reduce((function(t,e){return(t[e]=function(t){h.call(this,t,e)})&&t}),{})}function h(t,e){if(("object"==o(this.customHook)||null==o(this.customHook))&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var n=this.customHook.hook,i=["beforeDestroy","destroyed","onUnload","didUnmount","detached"].includes(e);for(var r in n){var a,c=n[r];c.name==e?c.cycleStart():c.destroy==e&&c.cycleEnd(),i&&(null===(a=c.unwatchFn)||void 0===a||a.call(c))}i&&delete this.customHook}}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=H[t.userAgentKey]),l=i,y=n,t.mixin(e(e({},s(v)),{},a({},j.initHook,(function(t){u.call(this,t,"page",void 0,j.initHook)})),"miniprogram"===j.name?a(a(a(a(a(a({},j.initHookApp,(function(t){u.call(this,t,"app",void 0,j.initHookApp)})),j.initHookComponentWx,(function(t,e){u.call(this,e,"component",t,j.initHookComponentWx)})),j.initHookComponentAlipayInit,(function(t,e){u.call(this,e,"component",t,j.initHookComponentAlipayInit)})),j.initHookComponentAlipay,(function(t,e){c.call(this,t,e,j.initHookComponentAlipay)})),"lifetimes",e(e({},s(k)),{},a({},j.initHookComponentLifetimes,(function(t,e){c.call(this,t,e,j.initHookComponentLifetimes)})))),"pageLifetimes",e({},s(g))):{}))},O=Object.freeze({__proto__:null,get BASE(){return j},install:A}),S={mixin:function(t){var e=this,o=App,n=Page,i=Component;App=function(n){e.mergeHook(t,n),o(n)},Page=function(o){e.mergeHook(t,o),n(o)},Component=function(o){e.mergeComponentHook(t,o);var n=e.mixinLifetimes(t,o);i(n)}},mergeHook:function(t,e){for(var o=function(){var t=c(i[n],2),o=t[0],r=t[1],a=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;o=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(c)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=c(o.value,2),n=t[0],i=t[1],r=e[n];e[n]=function(){for(var t=arguments.length,o=new Array(t),n=0;n", "homepage": "https://github.com/1977474741/spa-custom-hooks.git",