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] [8/50] Commit f79bbd5: more cleanly split client/server; set title
Date Fri, 22 Jan 2016 02:40:52 GMT
Commit f79bbd5b065f12e85be9a2e2daad9f2282136b99:
    more cleanly split client/server; set title


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

------------------------------------------------------------
views/main.js.rb                                             | ++++ -----
------------------------------------------------------------
64 changes: 30 additions, 34 deletions.
------------------------------------------------------------


diff --git a/views/main.js.rb b/views/main.js.rb
index 0b4b05a..61ec85c 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -1,31 +1,10 @@
 class Main < React
-  def initialize
-    Agenda.load(@@parsed)
-    Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
-    Agenda._agendas = @@agendas
-  end
-
-  def componentWillMount()
-    Main.navigate = self.navigate
-    self.navigate(@@path, true)
-  end
-
-  def navigate(path, replace)
+  def route(path)
     if path
-      item = Agenda.find(path)
+      @item = Agenda.find(path)
     else
-      item = Agenda
+      @item = Agenda
     end
-
-    if defined? history
-      if replace
-        history.replaceState({path: path}, nil, path)
-      else
-        history.pushState({path: path}, nil, path)
-      end
-    end
-
-    @item = item
   end
 
   def render
@@ -54,9 +33,35 @@ def render
     end
   end
 
+  def componentWillMount()
+    Agenda.load(@@parsed)
+    Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+    Agenda._agendas = @@agendas
+    self.route(@@path)
+  end
+
+  def navigate(path)
+    self.route(path)
+    history.pushState({path: path}, nil, path)
+    document.getElementsByTagName('title')[0].textContent = @item.title
+  end
+
   def componentDidMount()
+    Main.navigate = self.navigate
+    history.replaceState({path: @@path}, nil, @@path)
+    document.getElementsByTagName('title')[0].textContent = @item.title
+
     window.addEventListener :popstate do |event|
-      self.navigate(event.state.path, true)
+      self.route(event.state.path)
+      document.getElementsByTagName('title')[0].textContent = @item.title
+    end
+
+    def (document.getElementsByTagName('body')[0]).onkeyup(event)
+      if event.keyCode == 37
+        self.navigate document.querySelector("a[rel=prev]").getAttribute('href')
+      elsif event.keyCode == 39
+        self.navigate document.querySelector("a[rel=next]").getAttribute('href')
+      end
     end
 
     def window.onresize()
@@ -67,16 +72,7 @@ def window.onresize()
       main.style.marginBottom = "#{footer.clientHeight}px"
     end
 
-    document.getElementsByTagName('title')[0].textContent = @item.title
     window.onresize()
-
-    def (document.getElementsByTagName('body')[0]).onkeyup(event)
-      if event.keyCode == 37
-        self.navigate document.querySelector("a[rel=prev]").getAttribute('href')
-      elsif event.keyCode == 39
-        self.navigate document.querySelector("a[rel=next]").getAttribute('href')
-      end
-    end
   end
 
   def componentDidUpdate()

Mime
View raw message