mvc-pack
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -13,3 +13,3 @@ (function (root, factory) { | ||
// Package of combined patterns to build rich MVC modules | ||
// v0.9.4 | ||
// v0.9.5 | ||
// Copyright (c) 2016-2017 Valerii Zinchenko | ||
@@ -275,3 +275,3 @@ // Licensed under MIT (http://valerii-zinchenko.github.io/mvc-pack/blob/master/LICENSE.txt) | ||
*/ | ||
$el: null, | ||
element: null, | ||
@@ -282,3 +282,3 @@ /** | ||
destruct: function() { | ||
this.$el.remove(); | ||
this.element.remove(); | ||
this.control = null; | ||
@@ -323,18 +323,2 @@ | ||
/** | ||
* Show view. | ||
* Remove "hidden" class. | ||
*/ | ||
show: function() { | ||
this.$el.classList.remove('hidden'); | ||
}, | ||
/** | ||
* Hide view. | ||
* Add "hidden" class. | ||
*/ | ||
hide: function() { | ||
this.$el.classList.add('hidden'); | ||
}, | ||
/** | ||
* Initialize required for view elements. | ||
@@ -386,7 +370,23 @@ * | ||
var StaticView = SingletonClass(AView, function() { | ||
this.$el = document.querySelector(this.selector); | ||
this.element = document.querySelector(this.selector); | ||
}, /** @lends StaticView.prototype */{ | ||
selector: 'div', | ||
/** | ||
* Show view. | ||
* Remove "hidden" class. | ||
*/ | ||
show: function() { | ||
this.element.classList.remove('hidden'); | ||
}, | ||
/** | ||
* Hide view. | ||
* Add "hidden" class. | ||
*/ | ||
hide: function() { | ||
this.element.classList.add('hidden'); | ||
}, | ||
render: function() { | ||
@@ -396,3 +396,3 @@ this._initElements(); | ||
return this.$el; | ||
return this.element; | ||
} | ||
@@ -442,2 +442,14 @@ }); | ||
/** | ||
* Here are stored all separate elements which rendered from a tempalte | ||
* @type{HTMLCollection} | ||
*/ | ||
elements: [], | ||
/** | ||
* Container where the template elements will be created as real HTMLElements | ||
* @type {String} | ||
*/ | ||
_tmpContainer: 'div', | ||
/** | ||
* Render the view. | ||
@@ -452,14 +464,14 @@ * | ||
return this.$el; | ||
return this.elements; | ||
}, | ||
/** | ||
* Process view template and set the proceiing result to the [main view element]{@link $el}. | ||
* Process view template and set the processing result to the [main view element]{@link elements}. | ||
* The Model will be set to the template processor. | ||
*/ | ||
_processTemplate: function() { | ||
var _tmpel = document.createElement('div'); | ||
_tmpel.innerHTML = _.template(this.template)(this.model); | ||
this.element = document.createElement(this._tmpContainer); | ||
this.element.innerHTML = _.template(this.template)(this.model); | ||
this.$el = _tmpel.children[0]; | ||
this.elements = this.element.children; | ||
} | ||
@@ -466,0 +478,0 @@ }); |
// Package of combined patterns to build rich MVC modules | ||
// v0.9.4 | ||
// v0.9.5 | ||
// Copyright (c) 2016-2017 Valerii Zinchenko | ||
@@ -7,2 +7,2 @@ // Licensed under MIT (http://valerii-zinchenko.github.io/mvc-pack/blob/master/LICENSE.txt) | ||
!function(a,b){"function"==typeof define&&define.amd?define(["class-wrapper","lodash"],function(){return b.apply(null,arguments)}):"object"==typeof module&&module.exports?module.exports=b.apply(null,[require("class-wrapper"),require("lodash")]):a["mvc-pack"]=b.apply(null,[a["class-wrapper"],a.lodash])}(this,function(a,b){function c(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of the constructors. Object expected.");if(!g.is(a.View,"Function"))throw new Error("Incorrect type of a view's constructor. Expected: Function");if(a.Control&&!g.is(a.Control,"Function"))throw new Error("Incorrect type of a control's constructor. Expected: Function");return function(b,c){var d,e=new a.View(c);if(a.Decorators&&g.is(a.Decorators,"Object")){d={};for(var f in a.Decorators)g.is(a.Decorators[f],"Function")?d[f]=new a.Decorators[f](c):console.warn("Incompatible decorator's constructor: \""+f+'"! It should be inherited from an ADecorator')}var h;return a.Control&&(h=new a.Control(c)),new n({model:b,view:e,decorators:d,control:h,config:c})}}function d(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of an input argument. Expected: Object MVCConstructors");if(!g.is(a.Model,"Function"))throw new Error("Model constructor should be a function");if(!g.is(a.Modes,"Object"))throw new Error("Incorrect type for model's modes");for(var b in a.Modes)if(!g.is(a.Modes[b],"Function"))throw new Error('Incorrect type of a mode "'+b+'", Function expected');return g.is(a.Module,"Function")||(a.Module=o),function(b,c,d){var e,f=new(a.Model.bind.apply(a.Model,[null].concat(b))),g={};for(var h in a.Modes)d&&(e=d[h]),g[h]=new a.Modes[h](f,e);return new a.Module(f,g,c)}}var e=a.Class,f=a.SingletonClass,g={whatIs:function(a){return Object.prototype.toString.call(a)},is:function(a,b){return this.whatIs(a)==="[object "+b+"]"}},h=e(function(a){a&&g.is(a,"Object")&&(this.config=a)},{model:null,config:null,connect:function(){},destruct:function(){this.model=null,this.config=null},setModel:function(a){if(!g.is(a,"Object"))throw new Error("Model for the mode is not defined");this.model=a}}),i=e(h,null,{view:null,destruct:function(){this.view=null,h.prototype.destruct.call(this)},setView:function(a){if(!(a instanceof j))throw new Error("Incorrect type of view component");this.view=a}}),j=e(h,null,{control:null,$el:null,destruct:function(){this.$el.remove(),this.control=null,h.prototype.destruct.call(this)},setControl:function(a){if(!(a instanceof i))throw new Error("Incorrect type of control component");this.control=a},render:function(){},update:function(){},show:function(){this.$el.classList.remove("hidden")},hide:function(){this.$el.classList.add("hidden")},_initElements:function(){},_attachEvents:function(){}}),k=f(j,function(){this.$el=document.querySelector(this.selector)},{selector:"div",render:function(){return this._initElements(),this._attachEvents(),this.$el}}),l=e(j,null,{template:"<div></div>",render:function(){return this._processTemplate(),this._initElements(),this._attachEvents(),this.$el},_processTemplate:function(){var a=document.createElement("div");a.innerHTML=b.template(this.template)(this.model),this.$el=a.children[0]}}),m=e(l,null,{template:'<div><div class="component-container"></div></div>',_component:null,$component:null,setComponent:function(a){if(!(a instanceof j))throw new Error('Incorrect type of the "component" argument. Expected AView');this._component=a},destruct:function(){this._component&&this._component.destruct(),l.prototype.destruct.call(this)},render:function(){return l.prototype.render.call(this),this._component&&this.$component.appendChild(this._component.$el),this.$el},update:function(){this._component&&this._component.update(),l.prototype.update.call(this)},_processTemplate:function(){var a=document.createElement("div");a.innerHTML=b.template(this.template)({model:this.model,config:this.config}),this.$el=a.firstChild,this.$component=this.$el.querySelector(".component-container")}}),n=e(function(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of the mode's properties. Expected: Object");if(!g.is(a.model,"Object"))throw new Error("Incorrect type of the model. Expected: Object");if(!(a.view instanceof j))throw new Error("View should be inherited from AView");if(this.model=a.model,this._view=a.view,a.decorators&&g.is(a.decorators,"Object"))for(var b in a.decorators)a.decorators[b]instanceof m?this._decorators[b]=a.decorators[b]:console.warn("Incompatible decorator's constructor: \""+b+'"! It should be inherited from an ADecorator');a.control&&a.control instanceof i&&(this.control=a.control),this.view=this._view,this.connect()},{model:null,_view:null,view:null,control:null,_decorators:{},_isConnected:!1,connect:function(){if(!this._isConnected){this._view.setModel(this.model),this.control&&(this._view.setControl(this.control),this.control.setModel(this.model),this.control.setView(this._view),this.control.connect()),this._view.connect(),this._view.render();var a;for(var b in this._decorators)a=this._decorators[b],a.setModel(this.model),a.render();this._isConnected=!0}},decorateWith:function(a){if(a){if(g.is(a,"String"))return void this.decorateWith([a]);var b=this._view;if(this._decorators&&a.length>0)for(var c,d=0,e=a.length;d<e;d++)(c=this._decorators[a[d]])&&(c.setComponent(b),b=c);this.view=b}}}),o=e(function(a,b,c){if(!g.is(a,"Object")||!g.is(b,"Object"))throw new Error("Incorrect types of input arguments. Expected: Object model, Object modes");this.model=a,this.modes=b,g.is(c,"Object")&&(this.envModeMap=c)},{model:null,modes:null,envModeMap:{},getMode:function(a,b){var c=this.modes[a];return c&&b&&c.decorateWith(b),c||null},getModeFor:function(a,b){return this.getMode(this.envModeMap[a],b)}});return{AControl:i,AFMVCModule:d,AFMode:c,AModeComponent:h,AView:j,DynamicView:l,MVCModule:o,Mode:n,StaticView:k,utils:g}}); | ||
!function(a,b){"function"==typeof define&&define.amd?define(["class-wrapper","lodash"],function(){return b.apply(null,arguments)}):"object"==typeof module&&module.exports?module.exports=b.apply(null,[require("class-wrapper"),require("lodash")]):a["mvc-pack"]=b.apply(null,[a["class-wrapper"],a.lodash])}(this,function(a,b){function c(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of the constructors. Object expected.");if(!g.is(a.View,"Function"))throw new Error("Incorrect type of a view's constructor. Expected: Function");if(a.Control&&!g.is(a.Control,"Function"))throw new Error("Incorrect type of a control's constructor. Expected: Function");return function(b,c){var d,e=new a.View(c);if(a.Decorators&&g.is(a.Decorators,"Object")){d={};for(var f in a.Decorators)g.is(a.Decorators[f],"Function")?d[f]=new a.Decorators[f](c):console.warn("Incompatible decorator's constructor: \""+f+'"! It should be inherited from an ADecorator')}var h;return a.Control&&(h=new a.Control(c)),new n({model:b,view:e,decorators:d,control:h,config:c})}}function d(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of an input argument. Expected: Object MVCConstructors");if(!g.is(a.Model,"Function"))throw new Error("Model constructor should be a function");if(!g.is(a.Modes,"Object"))throw new Error("Incorrect type for model's modes");for(var b in a.Modes)if(!g.is(a.Modes[b],"Function"))throw new Error('Incorrect type of a mode "'+b+'", Function expected');return g.is(a.Module,"Function")||(a.Module=o),function(b,c,d){var e,f=new(a.Model.bind.apply(a.Model,[null].concat(b))),g={};for(var h in a.Modes)d&&(e=d[h]),g[h]=new a.Modes[h](f,e);return new a.Module(f,g,c)}}var e=a.Class,f=a.SingletonClass,g={whatIs:function(a){return Object.prototype.toString.call(a)},is:function(a,b){return this.whatIs(a)==="[object "+b+"]"}},h=e(function(a){a&&g.is(a,"Object")&&(this.config=a)},{model:null,config:null,connect:function(){},destruct:function(){this.model=null,this.config=null},setModel:function(a){if(!g.is(a,"Object"))throw new Error("Model for the mode is not defined");this.model=a}}),i=e(h,null,{view:null,destruct:function(){this.view=null,h.prototype.destruct.call(this)},setView:function(a){if(!(a instanceof j))throw new Error("Incorrect type of view component");this.view=a}}),j=e(h,null,{control:null,element:null,destruct:function(){this.element.remove(),this.control=null,h.prototype.destruct.call(this)},setControl:function(a){if(!(a instanceof i))throw new Error("Incorrect type of control component");this.control=a},render:function(){},update:function(){},_initElements:function(){},_attachEvents:function(){}}),k=f(j,function(){this.element=document.querySelector(this.selector)},{selector:"div",show:function(){this.element.classList.remove("hidden")},hide:function(){this.element.classList.add("hidden")},render:function(){return this._initElements(),this._attachEvents(),this.element}}),l=e(j,null,{template:"<div></div>",elements:[],_tmpContainer:"div",render:function(){return this._processTemplate(),this._initElements(),this._attachEvents(),this.elements},_processTemplate:function(){this.element=document.createElement(this._tmpContainer),this.element.innerHTML=b.template(this.template)(this.model),this.elements=this.element.children}}),m=e(l,null,{template:'<div><div class="component-container"></div></div>',_component:null,$component:null,setComponent:function(a){if(!(a instanceof j))throw new Error('Incorrect type of the "component" argument. Expected AView');this._component=a},destruct:function(){this._component&&this._component.destruct(),l.prototype.destruct.call(this)},render:function(){return l.prototype.render.call(this),this._component&&this.$component.appendChild(this._component.$el),this.$el},update:function(){this._component&&this._component.update(),l.prototype.update.call(this)},_processTemplate:function(){var a=document.createElement("div");a.innerHTML=b.template(this.template)({model:this.model,config:this.config}),this.$el=a.firstChild,this.$component=this.$el.querySelector(".component-container")}}),n=e(function(a){if(!g.is(a,"Object"))throw new Error("Incorrect type of the mode's properties. Expected: Object");if(!g.is(a.model,"Object"))throw new Error("Incorrect type of the model. Expected: Object");if(!(a.view instanceof j))throw new Error("View should be inherited from AView");if(this.model=a.model,this._view=a.view,a.decorators&&g.is(a.decorators,"Object"))for(var b in a.decorators)a.decorators[b]instanceof m?this._decorators[b]=a.decorators[b]:console.warn("Incompatible decorator's constructor: \""+b+'"! It should be inherited from an ADecorator');a.control&&a.control instanceof i&&(this.control=a.control),this.view=this._view,this.connect()},{model:null,_view:null,view:null,control:null,_decorators:{},_isConnected:!1,connect:function(){if(!this._isConnected){this._view.setModel(this.model),this.control&&(this._view.setControl(this.control),this.control.setModel(this.model),this.control.setView(this._view),this.control.connect()),this._view.connect(),this._view.render();var a;for(var b in this._decorators)a=this._decorators[b],a.setModel(this.model),a.render();this._isConnected=!0}},decorateWith:function(a){if(a){if(g.is(a,"String"))return void this.decorateWith([a]);var b=this._view;if(this._decorators&&a.length>0)for(var c,d=0,e=a.length;d<e;d++)(c=this._decorators[a[d]])&&(c.setComponent(b),b=c);this.view=b}}}),o=e(function(a,b,c){if(!g.is(a,"Object")||!g.is(b,"Object"))throw new Error("Incorrect types of input arguments. Expected: Object model, Object modes");this.model=a,this.modes=b,g.is(c,"Object")&&(this.envModeMap=c)},{model:null,modes:null,envModeMap:{},getMode:function(a,b){var c=this.modes[a];return c&&b&&c.decorateWith(b),c||null},getModeFor:function(a,b){return this.getMode(this.envModeMap[a],b)}});return{AControl:i,AFMVCModule:d,AFMode:c,AModeComponent:h,AView:j,DynamicView:l,MVCModule:o,Mode:n,StaticView:k,utils:g}}); |
@@ -45,3 +45,3 @@ /* | ||
*/ | ||
$el: null, | ||
element: null, | ||
@@ -52,3 +52,3 @@ /** | ||
destruct: function() { | ||
this.$el.remove(); | ||
this.element.remove(); | ||
this.control = null; | ||
@@ -93,18 +93,2 @@ | ||
/** | ||
* Show view. | ||
* Remove "hidden" class. | ||
*/ | ||
show: function() { | ||
this.$el.classList.remove('hidden'); | ||
}, | ||
/** | ||
* Hide view. | ||
* Add "hidden" class. | ||
*/ | ||
hide: function() { | ||
this.$el.classList.add('hidden'); | ||
}, | ||
/** | ||
* Initialize required for view elements. | ||
@@ -111,0 +95,0 @@ * |
@@ -42,2 +42,14 @@ /* | ||
/** | ||
* Here are stored all separate elements which rendered from a tempalte | ||
* @type{HTMLCollection} | ||
*/ | ||
elements: [], | ||
/** | ||
* Container where the template elements will be created as real HTMLElements | ||
* @type {String} | ||
*/ | ||
_tmpContainer: 'div', | ||
/** | ||
* Render the view. | ||
@@ -52,15 +64,15 @@ * | ||
return this.$el; | ||
return this.elements; | ||
}, | ||
/** | ||
* Process view template and set the proceiing result to the [main view element]{@link $el}. | ||
* Process view template and set the processing result to the [main view element]{@link elements}. | ||
* The Model will be set to the template processor. | ||
*/ | ||
_processTemplate: function() { | ||
var _tmpel = document.createElement('div'); | ||
_tmpel.innerHTML = _.template(this.template)(this.model); | ||
this.element = document.createElement(this._tmpContainer); | ||
this.element.innerHTML = _.template(this.template)(this.model); | ||
this.$el = _tmpel.children[0]; | ||
this.elements = this.element.children; | ||
} | ||
}); |
@@ -33,7 +33,23 @@ /* | ||
var StaticView = SingletonClass(AView, function() { | ||
this.$el = document.querySelector(this.selector); | ||
this.element = document.querySelector(this.selector); | ||
}, /** @lends StaticView.prototype */{ | ||
selector: 'div', | ||
/** | ||
* Show view. | ||
* Remove "hidden" class. | ||
*/ | ||
show: function() { | ||
this.element.classList.remove('hidden'); | ||
}, | ||
/** | ||
* Hide view. | ||
* Add "hidden" class. | ||
*/ | ||
hide: function() { | ||
this.element.classList.add('hidden'); | ||
}, | ||
render: function() { | ||
@@ -43,4 +59,4 @@ this._initElements(); | ||
return this.$el; | ||
return this.element; | ||
} | ||
}); |
{ | ||
"name": "mvc-pack", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"description": "Package of combined patterns to build rich MVC modules", | ||
@@ -5,0 +5,0 @@ "main": "dest/mvc-pack.js", |
@@ -49,3 +49,3 @@ 'use strict'; | ||
test('desctuct', function(){ | ||
aView.$el = document.createElement('div'); | ||
aView.element = document.createElement('div'); | ||
aView.setControl(new AControl({})); | ||
@@ -65,12 +65,3 @@ aView.destruct(); | ||
}); | ||
['show', 'hide'].forEach(function(method) { | ||
test(method + '()', function() { | ||
aView.$el = document.createElement('div'); | ||
assert.doesNotThrow(function(){ | ||
aView[method](); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -46,3 +46,11 @@ 'use strict'; | ||
}); | ||
['show', 'hide'].forEach(function(method) { | ||
test(method + '()', function() { | ||
view.element = document.createElement('div'); | ||
view[method](); | ||
}); | ||
}); | ||
}); | ||
}); |
101413
3144