Skip to content

Commit 7d0e448

Browse files
committed
Merge pull request #110 from Kanaye/master
Moved 'View._bindContext' to src/mv/bindContext.js.
2 parents 90163bd + 852a3ca commit 7d0e448

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

src/mvc/Application.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ define([
66
'./Model',
77
'./Collection',
88
'./View',
9-
'./Property'
10-
], function (blocks, clonePrototype, Router, History, Model, Collection, View, Property) {
9+
'./Property',
10+
'./bindContext'
11+
], function (blocks, clonePrototype, Router, History, Model, Collection, View, Property, bindContext) {
1112

1213
var application;
1314
blocks.Application = function (options) {
@@ -269,7 +270,7 @@ define([
269270

270271
extend: function (obj) {
271272
blocks.extend(this, obj);
272-
clonePrototype(obj, this);
273+
bindContext(this, obj);
273274
return this;
274275
},
275276

src/mvc/View.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
define([
22
'../core',
33
'../modules/ajax',
4-
'../modules/Events'
5-
], function (blocks, ajax, Events) {
4+
'../modules/Events',
5+
'./bindContext'
6+
], function (blocks, ajax, Events, bindContext) {
67
/**
78
* @namespace View
89
*/
910
function View(application, parentView) {
1011
var _this = this;
1112

12-
this._bindContext();
13+
bindContext(this);
1314
this._views = [];
1415
this._application = application;
1516
this._parentView = parentView || null;
@@ -149,21 +150,6 @@ define([
149150
this._application.navigateTo(view, params);
150151
},
151152

152-
_bindContext: function () {
153-
var key;
154-
var value;
155-
156-
for (key in this) {
157-
value = this[key];
158-
159-
if (blocks.isObservable(value)) {
160-
value.__context__ = this;
161-
} else if (blocks.isFunction(value)) {
162-
this[key] = blocks.bind(value, this);
163-
}
164-
}
165-
},
166-
167153
_tryInitialize: function (isActive) {
168154
if (!this._initialized && isActive) {
169155
if (this.options.url && !this._html) {

src/mvc/bindContext.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
define([
2+
'../core'
3+
], function (blocks) {
4+
function bindContext (context, object) {
5+
var key;
6+
var value;
7+
8+
if (!object) {
9+
object = context;
10+
}
11+
12+
for (key in object) {
13+
value = object[key];
14+
15+
if (blocks.isObservable(value)) {
16+
context[key].__context__ = context;
17+
} else if (blocks.isFunction(value)) {
18+
context[key] = blocks.bind(value, context);
19+
}
20+
21+
}
22+
}
23+
return bindContext;
24+
});

0 commit comments

Comments
 (0)