whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit 8d5bb15: start with stale data from local storage
Date Sat, 13 Feb 2016 16:21:13 GMT
Commit 8d5bb15da1a045bc79497fbb5c9ab32dcfb52754:
    start with stale data from local storage


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/roster/views/committerSearch.js.rb                       | +++++++++ ---
------------------------------------------------------------
22 changes: 17 additions, 5 deletions.
------------------------------------------------------------


diff --git a/www/roster/views/committerSearch.js.rb b/www/roster/views/committerSearch.js.rb
index d26937a..bb9db6a 100644
--- a/www/roster/views/committerSearch.js.rb
+++ b/www/roster/views/committerSearch.js.rb
@@ -7,15 +7,27 @@ def initialize
   end
 
   def componentDidMount()
+    # start with (possibly stale) data from local storage when available
+    ls_committers = localStorage.getItem('roster-committers')
+    if ls_committers
+      @committers = JSON.parse(ls_committers)
+      @ready = true
+      self.change(target: {value: @search}) unless @search.empty?
+    end
+
+    # load fresh data from the server
+    ls_committers = localStorage.getItem('roster-committers')
     Polyfill.require(%w(Promise fetch)) do
-      fetch('committer/index.json', credentials: 'include').then do |response|
+      fetch('committer/index.json', credentials: 'include').then {|response|
         response.json().then do |committers|
-          @ready = true
           @committers = committers
-          search = @search
-          self.change(target: {value: search}) unless search.empty?
+          @ready = true
+          self.change(target: {value: @search}) unless @search.empty?
+          localStorage.setItem('roster-committers', @committers.inspect)
         end
-      end
+      }.catch {|error|
+        console.log error
+      }
     end
   end
 

Mime
View raw message