componentjs-mvc
Version:
Abstract Classes for Model-View-Controller Component Roles
19 lines (18 loc) • 20 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ComponentJSMVC = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
var mkProperty=function(n,t,r,i){void 0===i&&(i=!0),Object.defineProperty(n,t,{configurable:!1,enumerable:!1,writable:i,value:r})},Latching=function(){mkProperty(this,"_latching_reg",{}),mkProperty(this,"_latching_cnt",0),mkProperty(this,"_latching_proc",{}),mkProperty(this,"_latching_plugin",{}),this.proc("none",function(){},function(){}),this.proc("pass",function(n){return n[0]},function(n,t){return t}),this.proc("or",function(){return!1},function(n,t){return n||t}),this.proc("and",function(){return!0},function(n,t){return n&&t}),this.proc("mult",function(){return 1},function(n,t){return n*t}),this.proc("add",function(){return 0},function(n,t){return n+t}),this.proc("append",function(){return""},function(n,t){return n+t}),this.proc("push",function(){return[]},function(n,t){return n.push(t),n}),this.proc("concat",function(){return[]},function(n,t){return n.concat(t)}),this.proc("insert",function(){return{}},function(n,t){return n[t]=!0,n}),this.proc("assign",function(){return{}},function(n,t){Object.keys(t).forEach(function(r){n[r]=t[r]})})};Latching.prototype={proc:function(n,t,r){if(3!==arguments.length)throw new Error("proc: invalid number of arguments");if("string"!=typeof n)throw new Error("proc: invalid name argument (has to be string)");if("function"!=typeof t)throw new Error("proc: invalid init argument (has to be function)");if("function"!=typeof r)throw new Error("proc: invalid step argument (has to be function)");return this._latching_proc[n]={init:t,step:r},this},at:function(){return this.latch.apply(this,arguments)},latch:function(n,t,r,i){if(arguments.length<2||arguments.length>4)throw new Error("latch: invalid number of arguments");void 0===this._latching_reg[n]&&(this._latching_reg[n]=[]);var o=this._latching_cnt++,e={id:o,cb:t,ctx:r};return i?this._latching_reg[n].unshift(e):this._latching_reg[n].push(e),o},unlatch:function(n,t){if(2!==arguments.length)throw new Error("unlatch: invalid number of arguments");if(void 0===this._latching_reg[n])throw new Error('unlatch: no such hook "'+n+'"');for(var r=-1,i=0;i<this._latching_reg[n].length;i++)if(this._latching_reg[n][i].id===t){r=i;break}if(-1===r)throw new Error("unlatch: no such latched callback");return this._latching_reg[n].splice(r,1),this},hook:function(n,t){if(arguments.length<2)throw new Error("hook: invalid number of arguments");if(void 0===this._latching_proc[t])throw new Error("hook: no such result processing defined");var r=Array.prototype.slice.call(arguments,2),i=this._latching_proc[t].init.call(null,r);if(void 0!==this._latching_reg[n])for(var o=0;o<this._latching_reg[n].length;o++){var e=this._latching_reg[n][o],c=!1,u=e.cb.apply(e.ctx,r.concat([i,function(){c=!0}]));if(i=this._latching_proc[t].step.call(null,i,u),c)break}return i},use:function(n,t){if("object"!=typeof n&&"function"!=typeof n)throw new Error("use: invalid plugin argument (object or function/class expected)");"function"==typeof n&&(n=new n);var r=this._latching_cnt++,i={id:r,plugin:n};if(this._latching_plugin[r]=i,"function"!=typeof n.use)throw new Error('use: invalid plugin (method "use" expected)');return void 0===t&&(t={}),n.use(this,t),r},unuse:function(n){if(1!==arguments.length)throw new Error("unuse: invalid number of arguments");if(void 0===this._latching_plugins[n])throw new Error("unuse: no such plugin found");var t=this._latching_plugins[n].plugin;return"function"==typeof t.unuse&&t.unuse(this),this._latching_plugins[n].plugin=null,delete this._latching_plugins[n],this}},module.exports=Latching;
},{}],2:[function(_dereq_,module,exports){
;function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=_default;var modelOf=function(e){if(e.marked("controller"))for(var t=e.children(),n=0;n<t.length;n++)if(t[n].marked("model"))return t[n];return e};function _default(e){return function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"cs",value:function(){return e.ComponentJS.apply(e,arguments)}},{key:"establish",value:function(){var t=this;this.__ComponentJS_MVC_comp||(this.__ComponentJS_MVC_comp={});for(var n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];"string"==typeof o[0]&&"string"==typeof o[1]||o.unshift("");var a=o[0],i=o[1],s=o[2],u=o[3],c=void 0===u||u,p=o[4],l=void 0!==p&&p;"object"===_typeof(s)&&s instanceof Array||(s=[s]);var f=s.map(function(e){return"function"==typeof e?new e:e}),_=""!==a?e.ComponentJS(this,a):e.ComponentJS(this);return _.create.apply(_,[i].concat(_toConsumableArray(f))),f.forEach(function(n){var o=e.ComponentJS(n),r=o.name();t.__ComponentJS_MVC_comp[r]=n,o.state_auto_increase(c),o.state_auto_decrease(l),e.hook("establish:post-create","none",{id:r,comp:o,obj:n})}),this}},{key:"demolish",value:function(t){var n=this;if(this.__ComponentJS_MVC_comp||(this.__ComponentJS_MVC_comp={}),void 0===t)Object.keys(this.__ComponentJS_MVC_comp).forEach(function(e){return n.unconstruct(e)});else{if(void 0===this.__ComponentJS_MVC_comp[t])throw new Error('demolish: no such component "'.concat(t,'"'));var o=this.__ComponentJS_MVC_comp[t],r=e.ComponentJS(o);e.hook("demolish:pre-destroy","none",{id:t,comp:r,obj:o}),r.destroy(),delete this.__ComponentJS_MVC_comp[t]}return this}},{key:"my",value:function(e){if(this.__ComponentJS_MVC_comp||(this.__ComponentJS_MVC_comp={}),void 0===this.__ComponentJS_MVC_comp[e])throw new Error('my: no such component "'.concat(e,'"'));return this.__ComponentJS_MVC_comp[e]}},{key:"exists",value:function(e){return this.__ComponentJS_MVC_comp&&this.__ComponentJS_MVC_comp[e]}},{key:"state",value:function(){var t;return(t=e.ComponentJS(this)).state.apply(t,arguments)}},{key:"guard",value:function(){var t;return(t=e.ComponentJS(this)).guard.apply(t,arguments)}},{key:"await",value:function(){var t;return(t=e.ComponentJS(this)).await.apply(t,arguments)}},{key:"spool",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=_extends({},{name:e.ComponentJS(this).state(),ctx:this},n,{func:t});return e.ComponentJS(this).spool(o),this}},{key:"observe",value:function(t,n){var o=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return"object"===_typeof(t)&&t instanceof Array||(t=[t]),t.forEach(function(t){var a=_extends({},{spool:e.ComponentJS(o).state(),noevent:!0},r,{name:t,func:function(){n.apply(void 0,arguments)}});modelOf(e.ComponentJS(o)).observe(a)}),this}},{key:"value",value:function(){var t;return(t=modelOf(e.ComponentJS(this))).value.apply(t,arguments)}},{key:"touch",value:function(){var t;return(t=modelOf(e.ComponentJS(this))).touch.apply(t,arguments),this}},{key:"subscribe",value:function(t,n){var o=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return"object"===_typeof(t)&&t instanceof Array||(t=[t]),t.forEach(function(t){var a=_extends({},{spool:e.ComponentJS(o).state(),noevent:!0,capturing:!1,spreading:!1,bubbling:!0},r,{name:t,func:n});return e.ComponentJS(o).subscribe(a)}),this}},{key:"publish",value:function(t,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n;"object"===_typeof(n)&&n instanceof Array||(r=[n]);var a=_extends({},{directresult:!0,capturing:!0,spreading:!1,bubbling:!0},o,{name:t,args:r});return e.ComponentJS(this).publish(a)}},{key:"register",value:function(t,n){var o=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return"object"===_typeof(t)&&t instanceof Array||(t=[t]),t.forEach(function(t){var a=_extends({},{spool:e.ComponentJS(o).state(),capturing:!1,spreading:!1,bubbling:!0},r,{name:t,func:n});return e.ComponentJS(o).register(a)}),this}},{key:"call",value:function(t,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n;"object"===_typeof(n)&&n instanceof Array||(r=[n]);var a=_extends({},{capturing:!0,spreading:!1,bubbling:!0},o,{name:t,args:r});return e.ComponentJS(this).call(a)}}]),t}()}
},{}],3:[function(_dereq_,module,exports){
;function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,o){return t&&_defineProperties(e.prototype,t),o&&_defineProperties(e,o),e}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _default(e){return function(t){function o(){return _classCallCheck(this,o),_possibleConstructorReturn(this,_getPrototypeOf(o).apply(this,arguments))}return _inherits(o,e.Component),_createClass(o,[{key:"$",value:function(){if("function"!=typeof e.jQuery)throw new Error("$: requires jQuery");return e.jQuery.apply(e,arguments)}},{key:"mask",value:function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e.ComponentJS.plugin("vue"))throw new Error("mask: requires ComponentJS Vue plugin");if("object"===_typeof(o.render)&&"function"==typeof o.render.render&&"object"===_typeof(o.render.staticRenderFns)&&o.render.staticRenderFns instanceof Array){var n=o.render,r=n.render,i=n.staticRenderFns;o.render=r,o.staticRenderFns=i}if(void 0===o.template&&void 0===o.render){if("function"!=typeof e.jQuery)throw new Error("mask: template-by-id requires jQuery");if("function"!=typeof e.jQuery.markup)throw new Error("mask: template-by-id requires jQuery Markup");o.template=e.jQuery.markup.render(t)}e.hook("mask:vue-options","none",{comp:e.ComponentJS(this),id:t,options:o});var u=e.ComponentJS(this).state(),f=e.ComponentJS(this).vue(o,u);return e.hook("mask:vue-result","none",{comp:e.ComponentJS(this),id:t,mask:f}),f}},{key:"socket",value:function(){for(var t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];if(3===o.length&&"object"===_typeof(o[0])&&"function"==typeof o[1]&&"function"==typeof o[2])o={ctx:o[0],plug:o[1],unplug:o[2]};else{if(1!==o.length||"object"!==_typeof(o[0]))throw new Error("socket: invalid arguments");o=o[0]}return void 0===o.spool&&(o.spool=e.ComponentJS(this).state()),e.ComponentJS(this).socket(o)}},{key:"link",value:function(){for(var t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];if(2===o.length&&"object"===_typeof(o[0])&&"string"==typeof o[1])o={target:o[0],socket:o[1]};else{if(1!==o.length||"object"!==_typeof(o[0]))throw new Error("link: invalid arguments");o=o[0]}return void 0===o.spool&&(o.spool=e.ComponentJS(this).state()),e.ComponentJS(this).link(o)}},{key:"plug",value:function(){for(var t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];if(1!==o.length||"object"!==_typeof(o[0])||void 0===o[0].object)o={object:o[0]};else{if(1!==o.length||"object"!==_typeof(o[0]))throw new Error("plug: invalid arguments");o=o[0]}return void 0===o.spool&&(o.spool=e.ComponentJS(this).state()),e.ComponentJS(this).plug(o)}}]),o}()}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=_default;
},{}],4:[function(_dereq_,module,exports){
;function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var o=0;o<e.length;o++){var r=e[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _createClass(t,e,o){return e&&_defineProperties(t.prototype,e),o&&_defineProperties(t,o),t}function _possibleConstructorReturn(t,e){return!e||"object"!==_typeof(e)&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _default(t){return function(e){function o(){return _classCallCheck(this,o),_possibleConstructorReturn(this,_getPrototypeOf(o).apply(this,arguments))}return _inherits(o,t.Component),_createClass(o,[{key:"model",value:function(){var e;return(e=t.ComponentJS(this)).model.apply(e,arguments)}}]),o}()}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=_default;
},{}],5:[function(_dereq_,module,exports){
;function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var o=0;o<e.length;o++){var r=e[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _createClass(t,e,o){return e&&_defineProperties(t.prototype,e),o&&_defineProperties(t,o),t}function _possibleConstructorReturn(t,e){return!e||"object"!==_typeof(e)&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _default(t){return function(e){function o(){return _classCallCheck(this,o),_possibleConstructorReturn(this,_getPrototypeOf(o).apply(this,arguments))}return _inherits(o,t.Component),_createClass(o,[{key:"sv",value:function(){return t.ComponentJS(this).property("sv")}}]),o}()}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=_default;
},{}],6:[function(_dereq_,module,exports){
;function _typeof(o){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _default=function(o){return function(){o.ComponentJS.plugin("mvc",function(t){t.latch("ComponentJS:comp-created",function(t){var e=t.obj();null!==e&&"object"===_typeof(e)&&(e instanceof o.View?t.mark("view"):e instanceof o.Model?t.mark("model"):e instanceof o.Controller&&t.mark("controller"))})})}};exports.default=_default;
},{}],7:[function(_dereq_,module,exports){
(function (global){
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _latching=_interopRequireDefault(_dereq_("latching")),_componentjsMvc0Component=_interopRequireDefault(_dereq_("./componentjs-mvc-0-component")),_componentjsMvc1View=_interopRequireDefault(_dereq_("./componentjs-mvc-1-view")),_componentjsMvc2Model=_interopRequireDefault(_dereq_("./componentjs-mvc-2-model")),_componentjsMvc3Controller=_interopRequireDefault(_dereq_("./componentjs-mvc-3-controller")),_componentjsMvc4Plugin=_interopRequireDefault(_dereq_("./componentjs-mvc-4-plugin"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var fatal=function(e){return function(){throw new Error(e)}},MVC=new _latching.default;MVC.ComponentJS=global.ComponentJS||fatal("ComponentJS missing"),MVC.jQuery=global.jQuery,MVC.Component=(0,_componentjsMvc0Component.default)(MVC),MVC.View=(0,_componentjsMvc1View.default)(MVC),MVC.Model=(0,_componentjsMvc2Model.default)(MVC),MVC.Controller=(0,_componentjsMvc3Controller.default)(MVC),MVC.Plugin=(0,_componentjsMvc4Plugin.default)(MVC);var _default=MVC;exports.default=_default;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./componentjs-mvc-0-component":2,"./componentjs-mvc-1-view":3,"./componentjs-mvc-2-model":4,"./componentjs-mvc-3-controller":5,"./componentjs-mvc-4-plugin":6,"latching":1}]},{},[2,3,4,5,6,7])(7)
});