strongloop / loopback-example-offline-sync

Offline sync, change tracking, and replication.
http://loopback.io/doc/en/lb2/Synchronization.html
Other
285 stars 110 forks source link

Easy-to-read GUIDs #62

Closed superkhau closed 9 years ago

superkhau commented 9 years ago

See outdated diff comment @ https://github.com/strongloop/loopback-example-offline-sync/pull/60#discussion_r28849823

- Todo.beforeSave = function(next, model) {

  • if (!model.id) model.id = 't-' + Math.floor(Math.random() * 10000).toString();
  • Todo.observe('before save', function(ctx, next) {
  • if (!ctx.Model.id)
  • ctx.Model.id = 't-' + Math.floor(Math.random() * 10000).toString();

This hook is no longer needed, the id property is initialised by loopback to a new GUID.

I think the idea here was to use small semi-unique numbers that are easier to read than full GUIDs.

I am proposing to make a following change in the GUI to make IDs easier to read:

take the first 8 characters of the generated uid (the 4 low bytes of the timestamp) use proquint- to convert these 8 characters into a readable string show this readable representation in all place where we were rendering the original id (mostly conflict >resolution views?) Feel free to make UI changes in a new pull request. However, the hook should be removed as part of this patch.

superkhau commented 9 years ago

@bajtos Is the idea to browserify proquint on the client and use it to render easy-to-read guids in Angular? Or should I be adding a before save hook on the common model that does the conversion before persisting it to the db?

bajtos commented 9 years ago

Is the idea to browserify proquint on the client and use it to render easy-to-read guids in Angular? Or should I be adding a before save hook on the common model that does the conversion before persisting it to the db?

The former. Change only the way how the id is rendered in the GUI, keep the underlying data structures unchanged.