error: function( msg ) {
throw msg;
},
- guid: function() {
- return +new Date() + Math.floor(Math.random()*11);
+ guid: function( prefix ) {
+ Popcorn.guid.counter++;
+ return ( prefix ? prefix : '' ) + ( +new Date() + Popcorn.guid.counter );
},
sizeOf: function ( obj ) {
var size = 0;
nop: function () {}
});
+ // Memoization property
+ Popcorn.guid.counter = 1;
+
// Simple Factory pattern to implement getters, setters and controllers
// as methods of the returned Popcorn instance. The immediately invoked function
// creates and returns an object of methods
if ( track.natives ) {
// supports user defined track event id
- track._id = !track.id ? track.natives.type + Popcorn.guid() : track.id;
+ track._id = !track.id ? Popcorn.guid( track.natives.type ) : track.id;
// Push track event ids into the history
obj.data.history.push( track._id );
});
+test("guid", function () {
+
+ expect(10);
+
+ var count = 3,
+ guids = [],
+ temp;
+
+ for ( var i = 0; i < count; i++ ) {
+
+ temp = Popcorn.guid();
+
+ ok( temp, "Popcorn.guid() returns value" );
+
+ if ( i > 0 ) {
+ notEqual( temp, guids[ guids.length - 1 ], "Current guid does not equal last guid" );
+ }
+
+ guids.push(temp);
+ }
+
+ guids = [];
+
+ for ( var i = 0; i < count; i++ ) {
+
+ temp = Popcorn.guid( "pre" );
+
+ ok( temp, "Popcorn.guid( 'pre' ) returns value" );
+
+ if ( i > 0 ) {
+ notEqual( temp, guids[ guids.length - 1 ], "Current guid does not equal last guid" );
+ }
+
+ guids.push(temp);
+ }
+
+});
+
+
test("Protected", function () {
expect(1);