UNPKG

wj-design-art

Version:

让javascript使用设计模式更简单

2 lines 4.39 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.wjDesignArt=e():t.wjDesignArt=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.instanceofCommand=e.deepCopy=e.isClass=void 0,e.isClass=function(t,e){if(void 0===e&&(e=!0),"function"!=typeof t)return!1;var n=t.toString();return void 0!==t.prototype&&(t.prototype.constructor===t&&("class"==n.slice(0,5)||(Object.getOwnPropertyNames(t.prototype).length>=2||!/^function\s+\(|^function\s+anonymous\(/.test(n)&&(!(!e||!/^function\s+[A-Z]/.test(n))||!!/\b\(this\b|\bthis[\.\[]\b/.test(n)&&(!(e&&!/classCallCheck\(this/.test(n))||/^function\sdefault_\d+\s*\(/.test(n))))))},e.deepCopy=function t(e){if(e instanceof Array){for(var n=[],r=0;r<e.length;++r)n[r]=t(e[r]);return n}if(e instanceof Object){n={};for(var o in e)n[o]=t(e[o]);return n}return e},e.instanceofCommand=function(t){return"function"==typeof t.execute}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=n(3),i=n(4);e.default={ResChain:r.default,singleCase:o.default,Command:i.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e,n){this.transaction=e,this.handleFn=t,this.next=n}return t.prototype.setNext=function(t){this.next=t},t.prototype.handle=function(t){var e=this;this.transaction=null!=t?t:this.transaction,this.handleFn.apply(this,[this.transaction]).then((function(t){var n;if(t.isNext){var r=null!==(n=t.nextTransaction)&&void 0!==n?n:e.transaction;e.next.handle(r)}}))},t}();e.default=r},function(t,e,n){"use strict";var r=this&&this.__spreadArrays||function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],u=0,s=i.length;u<s;u++,o++)r[o]=i[u];return r};Object.defineProperty(e,"__esModule",{value:!0});var o,i=n(0),u={singles:o={},add:function(t,e){void 0===e&&(e=t.name);for(var n=[],u=2;u<arguments.length;u++)n[u-2]=arguments[u];var s=Object.values(o),c=Object.keys(o),f=i.isClass(t,!0),a=s.some((function(e){return e instanceof t})),l=c.some((function(t){return t===e}));if(!f)throw new Error("非类不能创建单例");if(l)throw new Error("单例模式名称不能重名");a||(o[e]=new(t.bind.apply(t,r([void 0],n))),Object.defineProperty(o,e,{writable:!1}))},del:function(t){Reflect.deleteProperty(o,t)},clear:function(){for(var t in o)Reflect.deleteProperty(o,t)}};Object.defineProperty(u,"singles",{writable:!1}),e.default=u},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(0),o=function(){function t(){this.commandArr=[]}return t.prototype.add=function(t){return this.commandArr.push(t),this},t.prototype.remove=function(t){for(var e=0;e<this.commandArr.length;e++)this.commandArr[e]===t&&this.commandArr.splice(e,1);return this},t.prototype.undo=function(){return this.commandArr.pop(),this},t.prototype.reset=function(){return this.commandArr=[],this},t.prototype.execute=function(){this.commandArr.forEach((function(t,e){if(r.instanceofCommand(t)){if(!t.execute)throw new Error("该类不存在execute方法");t.execute()}else{if("function"!=typeof t)throw new Error("不符合命令模式的规则,要么是函数,要么是实现了ICommand接口的实例");t()}}))},t}();e.default=o}])})); //# sourceMappingURL=index.js.map