You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/02/13 17:21:13 UTC

[whimsy.git] [1/1] Commit 8d5bb15: start with stale data from local storage

Commit 8d5bb15da1a045bc79497fbb5c9ab32dcfb52754:
    start with stale data from local storage


Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@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