Opened 13 years ago

Closed 12 years ago

#8882 closed enhancement (wontfix)

Suggest bringing back generateUniqueId

Reported by: dante Owned by: anonymous
Priority: high Milestone:
Component: Core Version: 1.3.0b3
Keywords: Cc:
Blocked By: Blocking:


There are a couple of places in our codebase where we're doing some manual lookup for generating a unique ID (either DOM, or Dijit Widget ID, or function_exists() style checks [eg: jsonp callback generation]

I added a small function to plugd called dojo.unique which seems to cover all these use cases fine. Submitting this ticket to formally trac the request. (wontfix is fine, just looking for feedback). The only real limitation of my implementation is the ID counter is global, so dijit.byId checks and dojo.byId checks will increment together:

    var counter = 0, globalId = "";
    d.unique(testFn, base){
      do{ globalId = (base || "djid_") + (counter++); }
      return globalId;

and in this example, to get a uniuqe dom ID for your use:

var id = dojo.unique(dojo.byId);

or a jsonp callback:

var cb = dojo.unique(function(item){ return item in; });[cb] = function(){ ... }

The testFn is required, and may infinite loop if omitted. The function could handle this case, but is currently designed for size.

Change History (2)

comment:1 Changed 13 years ago by bill

Milestone: tbd1.4

1.3rc1 has been release; bumping remaining tickets to 1.4 (except for documentation/testing tickets)

comment:2 Changed 12 years ago by dante

Milestone: 1.4
Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.