Skip to content

Commit af04f3a

Browse files
committed
Shorter UIDs.
1 parent 655a2be commit af04f3a

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/model_model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
this.attributes = Model.Utils.extend({}, attributes)
44
this.changes = {}
55
this.errors = new Model.Errors(this)
6-
this.uid = [name, Model.UID.generate()].join("-")
6+
this.uid = Model.UID()
77
if (Model.Utils.isFunction(this.initialize)) this.initialize()
88
this.emit("initialize", this)
99
}

src/model_uid.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
Model.UID = {
2-
counter: 0,
1+
;(function(Model) {
2+
var counter = 0
33

4-
generate: function() {
5-
return [new Date().valueOf(), this.counter++].join("-")
6-
},
7-
8-
reset: function() {
9-
this.counter = 0
10-
return this
4+
Model.UID = function() {
5+
return [counter++, new Date().valueOf()].join("-")
116
}
12-
};
7+
})(Model)

test/tests/model_uid_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module("Model.UID")
22

33
test("UIDs shouldn't be the same", function() {
4-
var uid1 = Model.UID.generate()
5-
var uid2 = Model.UID.generate()
4+
var uid1 = Model.UID()
5+
var uid2 = Model.UID()
66

77
ok(uid1 !== uid2, uid1 + " shouldn't equal " + uid2)
88
})

0 commit comments

Comments
 (0)