smartxml: caching text nodes via expando
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 23 Jun 2014 13:38:51 +0000 (15:38 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 18 Jul 2014 09:47:37 +0000 (11:47 +0200)
src/smartxml/smartxml.js

index 9cff5ec..c0b3c42 100644 (file)
@@ -280,6 +280,7 @@ $.extend(ElementNode.prototype, {
 
 var TextNode = function(nativeNode, document) {
     DocumentNode.call(this, nativeNode, document);
+    nativeNode.__smartxmlTextNodeInstance = this;
 };
 TextNode.prototype = Object.create(DocumentNode.prototype);
 
@@ -360,7 +361,8 @@ $.extend(Document.prototype, Backbone.Events, fragments, {
         var cached;
 
         if(from instanceof Node) {
-            cached = ($(from).data(privateKey) || {}).node;
+            /* globals Text */
+            cached = from instanceof Text ? from.__smartxmlTextNodeInstance : ($(from).data(privateKey) || {}).node;
             if(cached instanceof DocumentNode) {
                 return cached;
             }