Skip to content

Commit

Permalink
add close view method to VM
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdao committed Aug 28, 2012
1 parent 5ee6a7f commit 396696b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Binary file added .DS_Store
Binary file not shown.
17 changes: 11 additions & 6 deletions vm.js
Expand Up @@ -4,10 +4,8 @@ window.VM = window.VM || {};
// VM.views hold all references to existing views
VM.views = VM.views || {};

// VM.createView always cleans up existing view before
// creating a new one.
// callback function always return a new view instance
VM.createView = function(name, callback) {
// Close view
VM.closeView = function(name) {
if (typeof VM.views[name] !== 'undefined') {
// Cleanup view
// Remove all of the view's delegated events
Expand All @@ -21,9 +19,16 @@ VM.createView = function(name, callback) {
VM.views[name].close();
}
}
};

// VM.createView always cleans up existing view before
// creating a new one.
// callback function always return a new view instance
VM.createView = function(name, callback) {
VM.closeView(name);
VM.views[name] = callback();
return VM.views[name];
}
};

// VM.reuseView always returns existing view. Otherwise it
// execute callback function to return new view
Expand All @@ -35,4 +40,4 @@ VM.reuseView = function(name, callback) {

VM.views[name] = callback();
return VM.views[name];
}
};

0 comments on commit 396696b

Please sign in to comment.