Changes between Initial Version and Version 11 of Ticket #8612


Ignore:
Timestamp:
May 22, 2009, 6:35:05 AM (11 years ago)
Author:
Eugene Lazutkin
Comment:

Replying to jburke:

  1. Yeah it is really bad. Any ideas? I didn't like the idea of attaching unique IDs to the nodes, but maybe adding a custom attribute with an ID on it would allow us to keep a hash/dictionary to weed out duplicates. I didn't like all that DOM twiddling, but it may be better than dojo.indexOf. The dojo.query _zip function might be instructional, but I have not fully digested it.

Yes, I think that Alex' solution is the most practical one. _zip looks complicated because Alex deals with IE XML. If we are to restrict the code to HTML it'll be simple. A sketch:

//private variables
var expandoName = "_dojoMarker", expandoValue = 0;

// the function
var _getUniqueAsNodeList = function(nodes){
  var ret = [], i = 0, node;
  ++expandoValue;
  // collect unique nodes using expando properties
  while(node = nodes[i++]){
    if(node.nodeType == 1 /*NODE*/){
      if(node[expandoName] !== expandoValue){
        node[expandoName] = expandoValue;
        ret.push(node);
      }
    }
  }
  // optional: cleanup
  for(i = 0; node = ret[i++];){
    delete node[expandoName]; // does it work on all browsers?
    // alternative: node[expandoName] = "";
  }
  return ret;
};

Alex doesn't clean up in his code opting for the smaller code base, and the faster execution at a price of a small baggage left on nodes. I think like usual he did the right choice.

In my code I decided to use the expando name, which tells that it came from Dojo. We can reuse his "_zipIdx".

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #8612

    • Property Cc dante added
    • Property Status changed from new to reopened
    • Property Milestone changed from 1.3 to 1.4
  • Ticket #8612 – Description

    initial v11  
    1 as discussed with pete, need to have some more sugar for plugd in NodeList in Base
     1as discussed with pete, need to have some more sugar for plugd in !NodeList in Base