Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add saveable#mergeNewest that takes timestamps into account.

  • Loading branch information...
commit 6b83c621f3b131883994cea9d77b72bf089c3978 1 parent 79df4c0
@fblee fblee authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 js/lib/saveable.js
View
13 js/lib/saveable.js
@@ -27,6 +27,19 @@ lib.saveable = function (_public, _protected, key) {
}
};
+ // Only integrate and save the hash of 'timestampedData' if its fetched_at
+ // property is a more recent (integer) timestamp than that which is already saved.
+ _public.mergeNewest = function (timestampedData) {
+ var saved = _public.fetch();
+
+ if (!saved || !saved.fetched_at || saved.fetched_at < timestampedData.fetched_at) {
+ _public.attributes(timestampedData);
+ _public.save();
+ } else {
+ _public.attributes(saved);
+ }
+ };
+
_public.clearStorage = function () {
lib.storage.setItem(key, undefined);
};
Please sign in to comment.
Something went wrong with that request. Please try again.