[Pkg-javascript-commits] [backbone] 22/34: Issue #33. Refactor towards View#_ensureElement

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.2.0
in repository backbone.

commit 705aff58a33c563575c278f5f1102d4ea7e704f0
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Wed Oct 20 14:41:50 2010 -0400

    Issue #33. Refactor towards View#_ensureElement
---
 backbone.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/backbone.js b/backbone.js
index d53e3f5..a2f43f2 100644
--- a/backbone.js
+++ b/backbone.js
@@ -515,14 +515,7 @@
   // if an existing element is not provided...
   Backbone.View = function(options) {
     this._configure(options || {});
-    if (this.options.el) {
-      this.el = this.options.el;
-    } else {
-      var attrs = {};
-      if (this.id) attrs.id = this.id;
-      if (this.className) attrs.className = this.className;
-      this.el = this.make(this.tagName, attrs);
-    }
+    this._ensureElement();
     if (this.initialize) this.initialize(options);
   };
 
@@ -603,10 +596,20 @@
       if (this.options) options = _.extend({}, this.options, options);
       if (options.model)      this.model      = options.model;
       if (options.collection) this.collection = options.collection;
+      if (options.el)         this.el         = options.el;
       if (options.id)         this.id         = options.id;
       if (options.className)  this.className  = options.className;
       if (options.tagName)    this.tagName    = options.tagName;
       this.options = options;
+    },
+
+    // Ensure that the View has a DOM element to render into.
+    _ensureElement : function() {
+      if (this.el) return;
+      var attrs = {};
+      if (this.id) attrs.id = this.id;
+      if (this.className) attrs.className = this.className;
+      this.el = this.make(this.tagName, attrs);
     }
 
   });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list