Skip to content

Commit

Permalink
Merge pull request #110 from Kanaye/master
Browse files Browse the repository at this point in the history
Moved 'View._bindContext' to src/mv/bindContext.js.
  • Loading branch information
astoilkov committed Nov 3, 2015
2 parents 90163bd + 852a3ca commit 7d0e448
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/mvc/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ define([
'./Model',
'./Collection',
'./View',
'./Property'
], function (blocks, clonePrototype, Router, History, Model, Collection, View, Property) {
'./Property',
'./bindContext'
], function (blocks, clonePrototype, Router, History, Model, Collection, View, Property, bindContext) {

var application;
blocks.Application = function (options) {
Expand Down Expand Up @@ -269,7 +270,7 @@ define([

extend: function (obj) {
blocks.extend(this, obj);
clonePrototype(obj, this);
bindContext(this, obj);
return this;
},

Expand Down
22 changes: 4 additions & 18 deletions src/mvc/View.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
define([
'../core',
'../modules/ajax',
'../modules/Events'
], function (blocks, ajax, Events) {
'../modules/Events',
'./bindContext'
], function (blocks, ajax, Events, bindContext) {
/**
* @namespace View
*/
function View(application, parentView) {
var _this = this;

this._bindContext();
bindContext(this);
this._views = [];
this._application = application;
this._parentView = parentView || null;
Expand Down Expand Up @@ -149,21 +150,6 @@ define([
this._application.navigateTo(view, params);
},

_bindContext: function () {
var key;
var value;

for (key in this) {
value = this[key];

if (blocks.isObservable(value)) {
value.__context__ = this;
} else if (blocks.isFunction(value)) {
this[key] = blocks.bind(value, this);
}
}
},

_tryInitialize: function (isActive) {
if (!this._initialized && isActive) {
if (this.options.url && !this._html) {
Expand Down
24 changes: 24 additions & 0 deletions src/mvc/bindContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define([
'../core'
], function (blocks) {
function bindContext (context, object) {
var key;
var value;

if (!object) {
object = context;
}

for (key in object) {
value = object[key];

if (blocks.isObservable(value)) {
context[key].__context__ = context;
} else if (blocks.isFunction(value)) {
context[key] = blocks.bind(value, context);
}

}
}
return bindContext;
});

0 comments on commit 7d0e448

Please sign in to comment.