I've written a client-side application. I am now creating a backend for it to persist data, but am curious about GUID implementations.
Client side, I generate a Song object with a unique ID using the following JavaScript. It is based off of this StackOverflow post.
//Based off of: https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
generateGuid: function () {
var startStringFormat = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
var guid = startStringFormat.replace(/[xy]/g, function (c) {
var r = Math.floor(Math.random() * 16);
var v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return guid;
},
Now, I'm defining a class in C# to represent my Song object:
public class Song
{
public virtual Guid Id { get; set; }
public virtual Guid PlaylistId { get; set; }
public virtual int VideoId { get; set; }
public virtual string Url { get; set; }
public virtual string Title { get; set; }
public virtual int Duration { get; set; }
}
Doing so got me wondering about the implications of the interacting Guid objects. Can I just take all of the Song objects I have in localStorage and do a direct translation of their Guids? Should I regenerate all of them?