From 0b9417e8ecbe4db8a8725f22af8d3c82758ccb02 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 1 Dec 2023 10:22:56 +0000 Subject: [PATCH] chore(release): 1.3.0 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # [1.3.0](https://github.com/1977474741/spa-custom-hooks/compare/v1.2.7...v1.3.0) (2023-12-01) ### Bug Fixes * 优化构建方式 ([21a7608](https://github.com/1977474741/spa-custom-hooks/commit/21a760884d499cc4fb6498533b28481a1345eeb8)) ### Features * 支持所有小程序的组件钩子,包括lifetimes 和 pageLifetimes,优化钩子匹配分割算法,适配uniapp钩子 ([3662a19](https://github.com/1977474741/spa-custom-hooks/commit/3662a19b8ae69aaea8756200fc32241860c4bad1)) --- CHANGELOG.md | 12 ++++++++++++ lib/spa-custom-hooks.js | 2 +- lib/spa-custom-hooks.mjs | 2 +- package.json | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df5b8b4..d7ffd41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ 更新日志 +# [1.3.0](https://github.com/1977474741/spa-custom-hooks/compare/v1.2.7...v1.3.0) (2023-12-01) + + +### Bug Fixes + +* 优化构建方式 ([21a7608](https://github.com/1977474741/spa-custom-hooks/commit/21a760884d499cc4fb6498533b28481a1345eeb8)) + + +### Features + +* 支持所有小程序的组件钩子,包括lifetimes 和 pageLifetimes,优化钩子匹配分割算法,适配uniapp钩子 ([3662a19](https://github.com/1977474741/spa-custom-hooks/commit/3662a19b8ae69aaea8756200fc32241860c4bad1)) + ## [1.2.7](https://github.com/1977474741/spa-custom-hooks/compare/v1.2.6...v1.2.7) (2023-07-27) diff --git a/lib/spa-custom-hooks.js b/lib/spa-custom-hooks.js index 4c1f56d..9d11ece 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:[]}}]),t}();function H(t){return t=(t=t.replace("on","")).substring(0,1).toUpperCase()+t.substring(1)}var O={"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:{hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=O["vue-miniprogram"],A=function(t,n,r,i){var a;function u(t){var e=y(this,j.hooksKey);j.isPage(e)&&(null!=r&&r.state||!i||(r.state=this[i]||i),this.customHook=new w(this,t,e))}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=O[t.userAgentKey]),f=r,k=n,t.mixin(e(e({},d.reduce((function(t,e){return(t[e]=function(t){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;for(var r in n){var i=n[r];i.name==e?i.cycleStart():i.destroy==e&&i.cycleEnd()}}})&&t}),{})),{},(c(a={},j.initHook,(function(t){u.call(this,t)})),c(a,j.initHookApp,(function(t){u.call(this,t)})),a)))},S=Object.freeze({__proto__:null,get BASE(){return j},install:A}),P={mixin:function(t){var e=this,o=Page,n=App;Page=function(n){e.mergeHook(t,n),o(n)},App=function(o){e.mergeHook(t,o),n(o)}},mergeHook:function(t,e){for(var o=function(){var t=a(r[n],2),o=t[0],i=t[1],c=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;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}(),b={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage(){return this.supportComponent}}},H=b["vue-miniprogram"],j=function(t,o,n,i){function r(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 s.call(this,e,o)}a.call(this,e,"component",t,o)}function a(t,e,o,r){if(!this.customHook){var a=f(this,H.hooksKey);if(H.isPage(a)){!n.state&&i&&(n.state=this[i]||i);var c="component"===e;Object.defineProperty(this,"customHook",{value:new w({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:r}),configurable:!0,enumerable:!1})}}}function c(t){return t.reduce((function(t,e){return(t[e]=function(t){s.call(this,t,e)})&&t}),{})}function s(t,e){if(("object"==typeof this.customHook||null==typeof this.customHook)&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var o=this.customHook.hook,n=["beforeDestroy","destroyed","onUnload"].includes(e);for(var i in o){var r=o[i];r.name==e?r.cycleStart():r.destroy==e&&r.cycleEnd(),n&&r.unwatchFn&&r.unwatchFn()}n&&delete this.customHook}}t.mpvueVersion?H.initHook="onLoad":t.userAgentKey&&(H=b[t.userAgentKey]),h=n,d=o,t.mixin(e(e({},c(g)),{},{[H.initHook](t){a.call(this,t,"page",void 0,H.initHook)}},"miniprogram"===H.name?{[H.initHookApp](t){a.call(this,t,"app",void 0,H.initHookApp)},[H.initHookComponentWx](t,e){a.call(this,e,"component",t,H.initHookComponentWx)},[H.initHookComponentAlipayInit](t,e){a.call(this,e,"component",t,H.initHookComponentAlipayInit)},[H.initHookComponentAlipay](t,e){r.call(this,t,e,H.initHookComponentAlipay)},lifetimes:e(e({},c(y)),{},{[H.initHookComponentLifetimes](t,e){r.call(this,t,e,H.initHookComponentLifetimes)}}),pageLifetimes:e({},c(k))}:{}))},A=Object.freeze({__proto__:null,get BASE(){return H},install:j}),O={mixin(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(t,e){for(var o=function(){var t=a(i[n],2),o=t[0],r=t[1],c=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,s=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){s=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(s)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=a(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:[]}}]),t}();function H(t){return t=(t=t.replace("on","")).substring(0,1).toUpperCase()+t.substring(1)}var O={"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:{hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",supportComponent:!0,isPage:function(){return this.supportComponent}}},j=O["vue-miniprogram"],A=function(t,n,r,i){var a;function u(t){var e=y(this,j.hooksKey);j.isPage(e)&&(null!=r&&r.state||!i||(r.state=this[i]||i),this.customHook=new w(this,t,e))}t.mpvueVersion?j.initHook="onLoad":t.userAgentKey&&(j=O[t.userAgentKey]),f=r,k=n,t.mixin(e(e({},d.reduce((function(t,e){return(t[e]=function(t){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;for(var r in n){var i=n[r];i.name==e?i.cycleStart():i.destroy==e&&i.cycleEnd()}}})&&t}),{})),{},(c(a={},j.initHook,(function(t){u.call(this,t)})),c(a,j.initHookApp,(function(t){u.call(this,t)})),a)))},S=Object.freeze({__proto__:null,get BASE(){return j},install:A}),P={mixin:function(t){var e=this,o=Page,n=App;Page=function(n){e.mergeHook(t,n),o(n)},App=function(o){e.mergeHook(t,o),n(o)}},mergeHook:function(t,e){for(var o=function(){var t=a(r[n],2),o=t[0],i=t[1],c=e[o];e[o]=function(){for(var t=arguments.length,e=new Array(t),o=0;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}(),b={"vue-h5":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage(t){return t._compiled&&this.supportComponent}},"vue-miniprogram":{hooksKey:"$options",initHook:"beforeCreate",supportComponent:!0,isPage(){return this.supportComponent}},miniprogram:{name:"miniprogram",hooksKey:"",initHook:"onLoad",initHookApp:"onLaunch",initHookComponentAlipay:"didMount",initHookComponentAlipayInit:"onInit",initHookComponentWx:"created",initHookComponentLifetimes:"created",supportComponent:!0,isPage(){return this.supportComponent}}},H=b["vue-miniprogram"],j=function(t,o,n,i){function r(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 s.call(this,e,o)}a.call(this,e,"component",t,o)}function a(t,e,o,r){if(!this.customHook){var a=f(this,H.hooksKey);if(H.isPage(a)){!n.state&&i&&(n.state=this[i]||i);var c="component"===e;Object.defineProperty(this,"customHook",{value:new w({instance:this,options:t,pageHooks:c?o:a,instanceType:e,initHookName:r}),configurable:!0,enumerable:!1})}}}function c(t){return t.reduce((function(t,e){return(t[e]=function(t){s.call(this,t,e)})&&t}),{})}function s(t,e){if(("object"==typeof this.customHook||null==typeof this.customHook)&&this.customHook.customHookArr.length){t&&Object.keys(t).length>0&&(this.customHook.options=t);var o=this.customHook.hook,n=["beforeDestroy","destroyed","onUnload"].includes(e);for(var i in o){var r=o[i];r.name==e?r.cycleStart():r.destroy==e&&r.cycleEnd(),n&&r.unwatchFn&&r.unwatchFn()}n&&delete this.customHook}}t.mpvueVersion?H.initHook="onLoad":t.userAgentKey&&(H=b[t.userAgentKey]),h=n,d=o,t.mixin(e(e({},c(g)),{},{[H.initHook](t){a.call(this,t,"page",void 0,H.initHook)}},"miniprogram"===H.name?{[H.initHookApp](t){a.call(this,t,"app",void 0,H.initHookApp)},[H.initHookComponentWx](t,e){a.call(this,e,"component",t,H.initHookComponentWx)},[H.initHookComponentAlipayInit](t,e){a.call(this,e,"component",t,H.initHookComponentAlipayInit)},[H.initHookComponentAlipay](t,e){r.call(this,t,e,H.initHookComponentAlipay)},lifetimes:e(e({},c(y)),{},{[H.initHookComponentLifetimes](t,e){r.call(this,t,e,H.initHookComponentLifetimes)}}),pageLifetimes:e({},c(k))}:{}))},A=Object.freeze({__proto__:null,get BASE(){return H},install:j}),O={mixin(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(t,e){for(var o=function(){var t=a(i[n],2),o=t[0],r=t[1],c=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,s=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return a=t.done,t},e:function(t){s=!0,r=t},f:function(){try{a||null==o.return||o.return()}finally{if(s)throw r}}}}(Object.entries(t).filter((function(t){return!n.includes(t[0])})));try{var r=function(){var t=a(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",