commonly-decorators
Advanced tools
Comparing version 0.5.3 to 0.6.1
@@ -407,8 +407,11 @@ import freezeClick from 'freeze-click'; | ||
} | ||
if (!this[pollingId]) { | ||
this[pollingId] = []; | ||
if (!this.__polling__list__) { | ||
this.__polling__list__ = Object.create(null); | ||
} | ||
if (!Array.isArray(this[pollingId])) { | ||
this[pollingId] = [this[pollingId]]; | ||
if (!this.__polling__list__[pollingId]) { | ||
this.__polling__list__[pollingId] = []; | ||
} | ||
if (!Array.isArray(this.__polling__list__[pollingId])) { | ||
this.__polling__list__[pollingId] = [this.__polling__list__[pollingId]]; | ||
} | ||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -427,4 +430,5 @@ var result, timer; | ||
timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this[pollingId] = this[pollingId].filter(function (item) { return item !== timer; }); | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
this.__polling__list__[pollingId] = (_b = (_a = this.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return item !== timer; }); | ||
clearTimeout(timer); | ||
@@ -435,3 +439,3 @@ fn.apply(this, opts); | ||
}); }, intervalTime); | ||
this[pollingId].push(timer); | ||
this.__polling__list__[pollingId].push(timer); | ||
return [2 /*return*/]; | ||
@@ -444,3 +448,3 @@ } | ||
target.onUnload = function newOnUnload() { | ||
var _a; | ||
var _a, _b; | ||
var opts = []; | ||
@@ -452,12 +456,12 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
var result; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
(_a = this === null || this === void 0 ? void 0 : this[pollingId]) === null || _a === void 0 ? void 0 : _a.forEach(function (item) { | ||
(_b = (_a = this === null || this === void 0 ? void 0 : this.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
this[pollingId] = null; | ||
this.__polling__list__[pollingId] = null; | ||
return [4 /*yield*/, originOnUnload.apply(this, opts)]; | ||
case 1: | ||
result = _b.sent(); | ||
result = _c.sent(); | ||
return [2 /*return*/, result]; | ||
@@ -471,9 +475,52 @@ } | ||
function PollingClear(content, pollingId) { | ||
var _a; | ||
var _a, _b; | ||
if (pollingId === void 0) { pollingId = "__polling__"; } | ||
(_a = content === null || content === void 0 ? void 0 : content[pollingId]) === null || _a === void 0 ? void 0 : _a.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
content[pollingId] = null; | ||
try { | ||
(_b = (_a = content.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
content.__polling__list__[pollingId] = null; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
function PollingClearAll(content) { | ||
try { | ||
Object.keys((content === null || content === void 0 ? void 0 : content.__polling__list__) || {}).forEach(function (pollingId) { | ||
var _a, _b, _c; | ||
(_b = (_a = content === null || content === void 0 ? void 0 : content.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
clearTimeout((_c = content === null || content === void 0 ? void 0 : content.__polling__list__) === null || _c === void 0 ? void 0 : _c[pollingId]); | ||
content.__polling__list__[pollingId] = null; | ||
}); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
function PollingClearAllDeco() { | ||
return function closurePollingClearAllDeco(target, property, descriptor) { | ||
var originFn = descriptor.value; | ||
descriptor.value = function fn() { | ||
var _this = this; | ||
var opts = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
opts[_i] = arguments[_i]; | ||
} | ||
var originResult = originFn.apply(this, opts); | ||
if (typeof originResult === "object" && | ||
typeof (originResult === null || originResult === void 0 ? void 0 : originResult.then) === "function") { | ||
return originResult.then(function () { | ||
PollingClearAll(_this); | ||
}, function () { | ||
PollingClearAll(_this); | ||
}); | ||
} | ||
PollingClearAll(this); | ||
return originResult; | ||
}; | ||
}; | ||
} | ||
@@ -485,3 +532,5 @@ var miniprogram = /*#__PURE__*/Object.freeze({ | ||
AssembleValue: AssembleValue, | ||
PollingClear: PollingClear | ||
PollingClear: PollingClear, | ||
PollingClearAll: PollingClearAll, | ||
PollingClearAllDeco: PollingClearAllDeco | ||
}); | ||
@@ -586,3 +635,3 @@ | ||
export { Assemble, AssembleValue, param as ParamDecorator, Polling, PollingClear, index as default, freeze }; | ||
export { Assemble, AssembleValue, param as ParamDecorator, Polling, PollingClear, PollingClearAll, PollingClearAllDeco, index as default, freeze }; | ||
//# sourceMappingURL=commonly-decorators.es.js.map |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("freeze-click")):"function"==typeof define&&define.amd?define(["exports","freeze-click"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).commonlyDecorators={},t.freezeClick)}(this,(function(t,n){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(n),o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},o(t,n)};function u(t,n,e,r){return new(e||(e=Promise))((function(o,u){function i(t){try{s(r.next(t))}catch(t){u(t)}}function a(t){try{s(r.throw(t))}catch(t){u(t)}}function s(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(i,a)}s((r=r.apply(t,n||[])).next())}))}function i(t,n){var e,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=n.call(t,i)}catch(t){u=[6,t],r=0}finally{e=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function a(t,n,e){if(e||2===arguments.length)for(var r,o=0,u=n.length;o<u;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}function s(t){return void 0===t&&(t=1e4),function(n,e,o){var a=o.value;o.value=r.default((function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return u(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,3,4]),[4,a.apply(this,n)];case 1:return[2,e.sent()];case 2:throw e.sent();case 3:return t.cancel(),[7];case 4:return[2]}}))}))}),t)}}function c(t,n,e){return function(r,o){var s=r[t];"function"==typeof s||"function"==typeof(null==s?void 0:s.then)?r[t]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return u(this,void 0,void 0,(function(){var r;return i(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),r=(t[0]?null==e?void 0:e.map((function(n){return t[0][n]})):[])||[],this[o]=new(n.bind.apply(n,a([void 0],r,!1))),[4,s.apply(this,t)];case 1:return[2,u.sent()];case 2:throw u.sent();case 3:return[2]}}))}))}:r[t]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return u(this,void 0,void 0,(function(){var r;return i(this,(function(u){try{r=(t[0]?null==e?void 0:e.map((function(n){return t[0][n]})):[])||[],this[o]=new(n.bind.apply(n,a([void 0],r,!1)))}catch(t){console.error(t)}return[2]}))}))}}}function l(t,n){return function(e,r){var o=e[t];"function"==typeof o||"function"==typeof(null==o?void 0:o.then)?e[t]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return u(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this[r]=n,[4,o.apply(this,t)];case 1:return[2,e.sent()];case 2:throw e.sent();case 3:return[2]}}))}))}:e[t]=function(){return u(this,void 0,void 0,(function(){return i(this,(function(t){try{this[r]=n}catch(t){console.error(t)}return[2]}))}))}}}var f=function(){function t(t,n,e){void 0===n&&(n=null),void 0===e&&(e="success"),this.msg="",this.extraData=null,this.status=t,this.data=n,this.msg=e}return t.prototype.getStatus=function(){return this.status},t.prototype.getData=function(){return this.data},t.prototype.getMsg=function(){return this.msg},t.prototype.setMsg=function(t){this.msg=t},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(t){this.extraData=t},t.isOk=function(t){return h(t)&&"ok"===t.getStatus()},t.isFail=function(t){return h(t)&&"fail"===t.getStatus()},t.isDeny=function(t){return h(t)&&"deny"===t.getStatus()},t.hasData=function(t){if(!t||"function"!=typeof t.getData)return!1;var n=t.getData();return!(null==n)},t.isNetWorkError=function(n){return t.getStatusIsFunction(n)&&"NETWORK_ERROR"===n.getStatus()||"NETWORK_ERROR"===(null==n?void 0:n.status)},t.cover=function(n,e){t[n]=e},t.success=function(n){return new t("ok",n)},t.fail=function(n){var e=new t("fail",null);return e.setMsg(n||""),e},t.exception=function(n){return new t(n.getStatus(),n.getData(),n.getMsg())},t.deny=function(n){return new t("deny",null,n||"")},t.networkError=function(n){return new t("NETWORK_ERROR",null,n||"网络异常,请重试")},t.interrupt=function(n){return new t("INTERRUPT",null,n||"程序中断,请重试")},t.isInterrupt=function(n){return"INTERRUPT"===t.getStatusValue(n)},t.cancel=function(n){return new t("CANCEL",null,n||"网络异常,请重试")},t.isCancel=function(n){return"CANCEL"===t.getStatusValue(n)},t.error=function(t){return new this("ERROR",null,t||"程序中断,请重试")},t.isError=function(n){return"ERROR"===t.getStatusValue(n)},t.getStatusIsFunction=function(t){return t&&"function"==typeof t.getStatus},t.getStatusValue=function(n){var e;return t.getStatusIsFunction(n)?n.getStatus():null!==(e=null==n?void 0:n.status)&&void 0!==e?e:""},t}();function h(t){return t&&"function"==typeof t.getStatus}function p(t,n){return void 0===t&&(t=1e3),void 0===n&&(n="__polling__"),function(e,r,o){var a=o.value;o.value=function e(){for(var r=this,o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];return this[n]||(this[n]=[]),Array.isArray(this[n])||(this[n]=[this[n]]),new Promise((function(s){return u(r,void 0,void 0,(function(){var r,c,l=this;return i(this,(function(h){switch(h.label){case 0:return[4,a.apply(this,o)];case 1:return r=h.sent(),f.isOk(r)?(s(r),[2]):(c=setTimeout((function(){return u(l,void 0,void 0,(function(){return i(this,(function(t){return this[n]=this[n].filter((function(t){return t!==c})),clearTimeout(c),e.apply(this,o),[2]}))}))}),t),this[n].push(c),[2])}}))}))}))};var s=e.onUnload;e.onUnload=function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return u(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return null===(t=null==this?void 0:this[n])||void 0===t||t.forEach((function(t){clearTimeout(t)})),this[n]=null,[4,s.apply(this,e)];case 1:return[2,r.sent()]}}))}))}}}function d(t,n){var e;void 0===n&&(n="__polling__"),null===(e=null==t?void 0:t[n])||void 0===e||e.forEach((function(t){clearTimeout(t)})),t[n]=null}var v=Object.freeze({__proto__:null,Polling:p,Assemble:c,AssembleValue:l,PollingClear:d});var y=function(t){function n(n){var e=t.call(this,n)||this;return e.__id="ParameterDecoratorError",e.status="PARAM_ERROR",e.data=null,e.from="CheckParamRequired",e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}o(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}(n,t),n.prototype.setData=function(t){this.data=t},n.prototype.getData=function(){return this.data},n.prototype.setStatus=function(t){this.status=t},n.prototype.getStatus=function(){return this.status},n.prototype.setFrom=function(t){this.from=t},n.prototype.getFrom=function(){return this.from},n.isParameterDecoratorError=function(t){return t instanceof n||(null==t?void 0:t.__id)===new n("").__id},n}(Error);var g={Required:function(t,n){return void 0===n&&(n=""),function(e,r,o){(null==e?void 0:e.__requiredData)||(e.__requiredData=new Map),e.__requiredData.set(r,{index:o,errMsg:t,propertyPath:n})}},CheckParamRequired:function(t,n,e){var r=e.value;e.value=function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];return u(this,void 0,void 0,(function(){var o,u,a,s,c,l;return i(this,(function(i){switch(i.label){case 0:if(o=null==t?void 0:t.__requiredData,u=o.get(n),a=Number(null==u?void 0:u.index),s=null==u?void 0:u.propertyPath,c=(null==s?void 0:s.split("."))||[],l=c.reduce((function(t,n){return null==t||!n&&0!==n||"."===n?t:null==t?void 0:t[n]}),null==e?void 0:e[a]),!isNaN(a)&&(void 0===l||""===l||null===l))throw new y((null==u?void 0:u.errMsg)||"第".concat(a+1,"个参数必传"));return[4,r.apply(this,e)];case 1:return[2,i.sent()]}}))}))}},ParameterDecoratorError:y},_={freeze:s,miniprogram:v};t.Assemble=c,t.AssembleValue=l,t.ParamDecorator=g,t.Polling=p,t.PollingClear=d,t.default=_,t.freeze=s,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=commonly-decorators.min.js.map | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("freeze-click")):"function"==typeof define&&define.amd?define(["exports","freeze-click"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).commonlyDecorators={},t.freezeClick)}(this,(function(t,n){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(n),o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},o(t,n)};function i(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function l(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,l)}a((r=r.apply(t,n||[])).next())}))}function u(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function l(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}function a(t){return void 0===t&&(t=1e4),function(n,e,o){var l=o.value;o.value=r.default((function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return i(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,3,4]),[4,l.apply(this,n)];case 1:return[2,e.sent()];case 2:throw e.sent();case 3:return t.cancel(),[7];case 4:return[2]}}))}))}),t)}}function s(t,n,e){return function(r,o){var a=r[t];"function"==typeof a||"function"==typeof(null==a?void 0:a.then)?r[t]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return i(this,void 0,void 0,(function(){var r;return u(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),r=(t[0]?null==e?void 0:e.map((function(n){return t[0][n]})):[])||[],this[o]=new(n.bind.apply(n,l([void 0],r,!1))),[4,a.apply(this,t)];case 1:return[2,i.sent()];case 2:throw i.sent();case 3:return[2]}}))}))}:r[t]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return i(this,void 0,void 0,(function(){var r;return u(this,(function(i){try{r=(t[0]?null==e?void 0:e.map((function(n){return t[0][n]})):[])||[],this[o]=new(n.bind.apply(n,l([void 0],r,!1)))}catch(t){console.error(t)}return[2]}))}))}}}function c(t,n){return function(e,r){var o=e[t];"function"==typeof o||"function"==typeof(null==o?void 0:o.then)?e[t]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this[r]=n,[4,o.apply(this,t)];case 1:return[2,e.sent()];case 2:throw e.sent();case 3:return[2]}}))}))}:e[t]=function(){return i(this,void 0,void 0,(function(){return u(this,(function(t){try{this[r]=n}catch(t){console.error(t)}return[2]}))}))}}}var f=function(){function t(t,n,e){void 0===n&&(n=null),void 0===e&&(e="success"),this.msg="",this.extraData=null,this.status=t,this.data=n,this.msg=e}return t.prototype.getStatus=function(){return this.status},t.prototype.getData=function(){return this.data},t.prototype.getMsg=function(){return this.msg},t.prototype.setMsg=function(t){this.msg=t},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(t){this.extraData=t},t.isOk=function(t){return _(t)&&"ok"===t.getStatus()},t.isFail=function(t){return _(t)&&"fail"===t.getStatus()},t.isDeny=function(t){return _(t)&&"deny"===t.getStatus()},t.hasData=function(t){if(!t||"function"!=typeof t.getData)return!1;var n=t.getData();return!(null==n)},t.isNetWorkError=function(n){return t.getStatusIsFunction(n)&&"NETWORK_ERROR"===n.getStatus()||"NETWORK_ERROR"===(null==n?void 0:n.status)},t.cover=function(n,e){t[n]=e},t.success=function(n){return new t("ok",n)},t.fail=function(n){var e=new t("fail",null);return e.setMsg(n||""),e},t.exception=function(n){return new t(n.getStatus(),n.getData(),n.getMsg())},t.deny=function(n){return new t("deny",null,n||"")},t.networkError=function(n){return new t("NETWORK_ERROR",null,n||"网络异常,请重试")},t.interrupt=function(n){return new t("INTERRUPT",null,n||"程序中断,请重试")},t.isInterrupt=function(n){return"INTERRUPT"===t.getStatusValue(n)},t.cancel=function(n){return new t("CANCEL",null,n||"网络异常,请重试")},t.isCancel=function(n){return"CANCEL"===t.getStatusValue(n)},t.error=function(t){return new this("ERROR",null,t||"程序中断,请重试")},t.isError=function(n){return"ERROR"===t.getStatusValue(n)},t.getStatusIsFunction=function(t){return t&&"function"==typeof t.getStatus},t.getStatusValue=function(n){var e;return t.getStatusIsFunction(n)?n.getStatus():null!==(e=null==n?void 0:n.status)&&void 0!==e?e:""},t}();function _(t){return t&&"function"==typeof t.getStatus}function p(t,n){return void 0===t&&(t=1e3),void 0===n&&(n="__polling__"),function(e,r,o){var l=o.value;o.value=function e(){for(var r=this,o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];return this.__polling__list__||(this.__polling__list__=Object.create(null)),this.__polling__list__[n]||(this.__polling__list__[n]=[]),Array.isArray(this.__polling__list__[n])||(this.__polling__list__[n]=[this.__polling__list__[n]]),new Promise((function(a){return i(r,void 0,void 0,(function(){var r,s,c=this;return u(this,(function(_){switch(_.label){case 0:return[4,l.apply(this,o)];case 1:return r=_.sent(),f.isOk(r)?(a(r),[2]):(s=setTimeout((function(){return i(c,void 0,void 0,(function(){var t,r;return u(this,(function(i){return this.__polling__list__[n]=null===(r=null===(t=this.__polling__list__)||void 0===t?void 0:t[n])||void 0===r?void 0:r.filter((function(t){return t!==s})),clearTimeout(s),e.apply(this,o),[2]}))}))}),t),this.__polling__list__[n].push(s),[2])}}))}))}))};var a=e.onUnload;e.onUnload=function(){for(var t,e,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return i(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return null===(e=null===(t=null==this?void 0:this.__polling__list__)||void 0===t?void 0:t[n])||void 0===e||e.forEach((function(t){clearTimeout(t)})),this.__polling__list__[n]=null,[4,a.apply(this,r)];case 1:return[2,o.sent()]}}))}))}}}function h(t,n){var e,r;void 0===n&&(n="__polling__");try{null===(r=null===(e=t.__polling__list__)||void 0===e?void 0:e[n])||void 0===r||r.forEach((function(t){clearTimeout(t)})),t.__polling__list__[n]=null}catch(t){console.error(t)}}function v(t){try{Object.keys((null==t?void 0:t.__polling__list__)||{}).forEach((function(n){var e,r,o;null===(r=null===(e=null==t?void 0:t.__polling__list__)||void 0===e?void 0:e[n])||void 0===r||r.forEach((function(t){clearTimeout(t)})),clearTimeout(null===(o=null==t?void 0:t.__polling__list__)||void 0===o?void 0:o[n]),t.__polling__list__[n]=null}))}catch(t){console.error(t)}}function d(){return function(t,n,e){var r=e.value;e.value=function(){for(var t=this,n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var o=r.apply(this,n);return"object"==typeof o&&"function"==typeof(null==o?void 0:o.then)?o.then((function(){v(t)}),(function(){v(t)})):(v(this),o)}}}var g=Object.freeze({__proto__:null,Polling:p,Assemble:s,AssembleValue:c,PollingClear:h,PollingClearAll:v,PollingClearAllDeco:d});var y=function(t){function n(n){var e=t.call(this,n)||this;return e.__id="ParameterDecoratorError",e.status="PARAM_ERROR",e.data=null,e.from="CheckParamRequired",e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}o(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}(n,t),n.prototype.setData=function(t){this.data=t},n.prototype.getData=function(){return this.data},n.prototype.setStatus=function(t){this.status=t},n.prototype.getStatus=function(){return this.status},n.prototype.setFrom=function(t){this.from=t},n.prototype.getFrom=function(){return this.from},n.isParameterDecoratorError=function(t){return t instanceof n||(null==t?void 0:t.__id)===new n("").__id},n}(Error);var b={Required:function(t,n){return void 0===n&&(n=""),function(e,r,o){(null==e?void 0:e.__requiredData)||(e.__requiredData=new Map),e.__requiredData.set(r,{index:o,errMsg:t,propertyPath:n})}},CheckParamRequired:function(t,n,e){var r=e.value;e.value=function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];return i(this,void 0,void 0,(function(){var o,i,l,a,s,c;return u(this,(function(u){switch(u.label){case 0:if(o=null==t?void 0:t.__requiredData,i=o.get(n),l=Number(null==i?void 0:i.index),a=null==i?void 0:i.propertyPath,s=(null==a?void 0:a.split("."))||[],c=s.reduce((function(t,n){return null==t||!n&&0!==n||"."===n?t:null==t?void 0:t[n]}),null==e?void 0:e[l]),!isNaN(l)&&(void 0===c||""===c||null===c))throw new y((null==i?void 0:i.errMsg)||"第".concat(l+1,"个参数必传"));return[4,r.apply(this,e)];case 1:return[2,u.sent()]}}))}))}},ParameterDecoratorError:y},w={freeze:a,miniprogram:g};t.Assemble=s,t.AssembleValue=c,t.ParamDecorator=b,t.Polling=p,t.PollingClear=h,t.PollingClearAll=v,t.PollingClearAllDeco=d,t.default=w,t.freeze=a,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=commonly-decorators.min.js.map |
@@ -39,3 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PollingClear = void 0; | ||
exports.PollingClearAllDeco = exports.PollingClearAll = exports.PollingClear = void 0; | ||
var return_data_1 = require("return-data"); | ||
@@ -53,8 +53,11 @@ function Polling(intervalTime, pollingId) { | ||
} | ||
if (!this[pollingId]) { | ||
this[pollingId] = []; | ||
if (!this.__polling__list__) { | ||
this.__polling__list__ = Object.create(null); | ||
} | ||
if (!Array.isArray(this[pollingId])) { | ||
this[pollingId] = [this[pollingId]]; | ||
if (!this.__polling__list__[pollingId]) { | ||
this.__polling__list__[pollingId] = []; | ||
} | ||
if (!Array.isArray(this.__polling__list__[pollingId])) { | ||
this.__polling__list__[pollingId] = [this.__polling__list__[pollingId]]; | ||
} | ||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -73,4 +76,5 @@ var result, timer; | ||
timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this[pollingId] = this[pollingId].filter(function (item) { return item !== timer; }); | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
this.__polling__list__[pollingId] = (_b = (_a = this.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return item !== timer; }); | ||
clearTimeout(timer); | ||
@@ -81,3 +85,3 @@ fn.apply(this, opts); | ||
}); }, intervalTime); | ||
this[pollingId].push(timer); | ||
this.__polling__list__[pollingId].push(timer); | ||
return [2 /*return*/]; | ||
@@ -90,3 +94,3 @@ } | ||
target.onUnload = function newOnUnload() { | ||
var _a; | ||
var _a, _b; | ||
var opts = []; | ||
@@ -98,12 +102,12 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
var result; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
(_a = this === null || this === void 0 ? void 0 : this[pollingId]) === null || _a === void 0 ? void 0 : _a.forEach(function (item) { | ||
(_b = (_a = this === null || this === void 0 ? void 0 : this.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
this[pollingId] = null; | ||
this.__polling__list__[pollingId] = null; | ||
return [4 /*yield*/, originOnUnload.apply(this, opts)]; | ||
case 1: | ||
result = _b.sent(); | ||
result = _c.sent(); | ||
return [2 /*return*/, result]; | ||
@@ -118,10 +122,55 @@ } | ||
function PollingClear(content, pollingId) { | ||
var _a; | ||
var _a, _b; | ||
if (pollingId === void 0) { pollingId = "__polling__"; } | ||
(_a = content === null || content === void 0 ? void 0 : content[pollingId]) === null || _a === void 0 ? void 0 : _a.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
content[pollingId] = null; | ||
try { | ||
(_b = (_a = content.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
content.__polling__list__[pollingId] = null; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
exports.PollingClear = PollingClear; | ||
function PollingClearAll(content) { | ||
try { | ||
Object.keys((content === null || content === void 0 ? void 0 : content.__polling__list__) || {}).forEach(function (pollingId) { | ||
var _a, _b, _c; | ||
(_b = (_a = content === null || content === void 0 ? void 0 : content.__polling__list__) === null || _a === void 0 ? void 0 : _a[pollingId]) === null || _b === void 0 ? void 0 : _b.forEach(function (item) { | ||
clearTimeout(item); | ||
}); | ||
clearTimeout((_c = content === null || content === void 0 ? void 0 : content.__polling__list__) === null || _c === void 0 ? void 0 : _c[pollingId]); | ||
content.__polling__list__[pollingId] = null; | ||
}); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
exports.PollingClearAll = PollingClearAll; | ||
function PollingClearAllDeco() { | ||
return function closurePollingClearAllDeco(target, property, descriptor) { | ||
var originFn = descriptor.value; | ||
descriptor.value = function fn() { | ||
var _this = this; | ||
var opts = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
opts[_i] = arguments[_i]; | ||
} | ||
var originResult = originFn.apply(this, opts); | ||
if (typeof originResult === "object" && | ||
typeof (originResult === null || originResult === void 0 ? void 0 : originResult.then) === "function") { | ||
return originResult.then(function () { | ||
PollingClearAll(_this); | ||
}, function () { | ||
PollingClearAll(_this); | ||
}); | ||
} | ||
PollingClearAll(this); | ||
return originResult; | ||
}; | ||
}; | ||
} | ||
exports.PollingClearAllDeco = PollingClearAllDeco; | ||
//# sourceMappingURL=Polling.js.map |
{ | ||
"name": "commonly-decorators", | ||
"version": "0.5.3", | ||
"version": "0.6.1", | ||
"description": "some commonly decorators", | ||
@@ -5,0 +5,0 @@ "author": "yiri.zhou", |
export default function Polling(intervalTime?: number, pollingId?: string): (target: any, property: string, descriptor: PropertyDescriptor) => void; | ||
export declare function PollingClear(content: any, pollingId?: string): void; | ||
export declare function PollingClearAll(content: any): void; | ||
export declare function PollingClearAllDeco(): (target: any, property: string, descriptor: PropertyDescriptor) => void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141561
1500