Skip to content

Commit

Permalink
Made Observable lazy initialized so that inheriting objects are not r…
Browse files Browse the repository at this point in the history
…equired to call Observable constructor on their constructors
  • Loading branch information
otakustay committed Mar 9, 2013
1 parent adc8b95 commit a5c10e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ define(
* @extends Observable
*/
function Action() {
Observable.apply(this, arguments);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ define(
* @param {Object=} context 初始化的数据
*/
function Model(context) {
Observable.apply(this, arguments);

this._store = {};

if (context) {
Expand Down
12 changes: 12 additions & 0 deletions src/Observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ define(
* @public
*/
Observable.prototype.on = function(type, handler) {
if (!this._events) {
this._events = {};
}

var pool = this._events[type];
if (!pool) {
pool = this._events[type] = [];
Expand All @@ -45,6 +49,10 @@ define(
* @public
*/
Observable.prototype.un = function(type, handler) {
if (!this._events) {
return;
}

if (!handler) {
this._events[type] = [];
return;
Expand Down Expand Up @@ -85,6 +93,10 @@ define(
* @public
*/
Observable.prototype.fire = function(type, event) {
if (!this._events) {
return;
}

if (Object.prototype.toString.call(event) === '[object Object]') {
event.type = type;
}
Expand Down
1 change: 0 additions & 1 deletion src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define(
* @extends Observable
*/
function View() {
Observable.apply(this, arguments);
}

/**
Expand Down

0 comments on commit a5c10e3

Please sign in to comment.