whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] 03/05: broadcast latest changes to all clients
Date Tue, 05 Jun 2018 23:19:38 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

commit 2ceb85152f8b1372b2c09d33b7bbea960deca68d
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Tue Jun 5 09:02:34 2018 -0400

    broadcast latest changes to all clients
---
 www/board/agenda/views/sw.js.rb | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/www/board/agenda/views/sw.js.rb b/www/board/agenda/views/sw.js.rb
index edd1582..72e614f 100644
--- a/www/board/agenda/views/sw.js.rb
+++ b/www/board/agenda/views/sw.js.rb
@@ -53,11 +53,11 @@ def cache_replace(cache, request, response)
   cache.put(request, response)
 end
 
-# request all clients to reload content if css or js changed
-def reload()
+# broadcast a message to all clients
+def broadcast(type)
   clients.matchAll().then do |clients|
     clients.each do |client|
-      client.postMessage(type: 'reload')
+      client.postMessage(type: type)
     end
   end
 end
@@ -80,7 +80,7 @@ def preload(cache, base, text, toolate)
         fetch(request).then do |response|
           cache_replace(cache, request, response) if response.ok
           count -= 1
-          reload() if toolate and changed and count == 0
+          broadcast(:reload) if toolate and changed and count == 0
         end
       end
     end
@@ -99,7 +99,9 @@ def fetch_from_cache(event)
   end
 end
 
-# Return latest bootstrap page from the cache
+# Return latest bootstrap page from the cache; then update the bootstrap
+# from the server.  If the body has changed, broadcast that information to
+# all the browser window clients.
 def latest(event)
   return Promise.new do |fulfill, reject|
     caches.open('board/agenda').then do |cache|
@@ -112,10 +114,19 @@ def latest(event)
 	end
 
         if match
-          fulfill(match)
-
-          request = Request.new(match.url, cache: "no-store")
-          fetch(request).then {|response| cache.put request, response}
+          match.clone().text().then do |before|
+            fulfill(match)
+
+            request = Request.new(match.url, cache: "no-store")
+            fetch(request).then do |response| 
+              if response.ok
+                response.match().text().then do |after|
+                  cache.put request, response
+                  broadcast(:latest) if after != before
+                end
+              end
+            end
+          end
         else
           fetch(event.request).then(fulfill, reject)
         end

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

Mime
View raw message