whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] 02/02: modernize the javascript loops
Date Thu, 29 Aug 2019 20:12:28 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 07a0cc115d44d2107897d07d78eddd90f2e56935
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Thu Aug 29 16:05:39 2019 -0400

    modernize the javascript loops
    
    Object.entries is now supported in all browsers that support ServiceWorkers.
    
    Input is now more idiomatic Ruby.  ES5 output is generally equivalent.
    ES2017 output is more concise, efficient, and modern JavaScript.
    
    Search https://whimsy.apache.org/board/agenda/app.js for "Object.entries" to
    see examples of the changes.  Compare equivalent lines in
    https://whimsy.apache.org/board/agenda/app-es5.js to see the differences.
---
 www/board/agenda/Gemfile                              |  2 +-
 www/board/agenda/main.rb                              |  2 +-
 www/board/agenda/views/buttons/attend.js.rb           |  3 +--
 www/board/agenda/views/elements/additional-info.js.rb |  4 ++--
 www/board/agenda/views/elements/pns.rb                |  8 ++------
 www/board/agenda/views/layout/main.js.rb              |  4 ++--
 www/board/agenda/views/models/agenda.js.rb            |  4 ++--
 www/board/agenda/views/models/chat.js.rb              |  6 ++----
 www/board/agenda/views/models/minutes.js.rb           |  4 ++--
 www/board/agenda/views/models/pending.js.rb           |  9 ++++-----
 www/board/agenda/views/pages/action-items.js.rb       | 16 ++++++++--------
 www/board/agenda/views/pages/adjournment.js.rb        | 12 ++++++------
 www/board/agenda/views/pages/fy23.js.rb               |  6 +++---
 www/board/agenda/views/pages/report.js.rb             |  4 +---
 www/board/agenda/views/pages/roll-call.js.rb          |  7 +++----
 www/board/agenda/views/pages/shepherd.js.rb           | 10 +++++-----
 www/board/agenda/views/router.js.rb                   | 12 ++++++------
 17 files changed, 51 insertions(+), 62 deletions(-)

diff --git a/www/board/agenda/Gemfile b/www/board/agenda/Gemfile
index c6e5087..3f762f1 100644
--- a/www/board/agenda/Gemfile
+++ b/www/board/agenda/Gemfile
@@ -13,7 +13,7 @@ end
 
 gem 'rake'
 gem 'wunderbar'
-gem 'ruby2js', '>= 3.0.15'
+gem 'ruby2js', '>= 3.2.0'
 gem 'sinatra', '~> 2.0'
 gem 'nokogumbo'
 gem 'execjs', ('<2.5.1' if RUBY_VERSION =~ /^1/)
diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index 6321eea..5e4244d 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -10,7 +10,7 @@ require 'whimsy/asf/board'
 require 'wunderbar/sinatra'
 require 'wunderbar/vue'
 require 'wunderbar/bootstrap/theme'
-require 'ruby2js/es2015'
+require 'ruby2js/es2017'
 require 'ruby2js/strict'
 require 'ruby2js/filter/functions'
 require 'ruby2js/filter/require'
diff --git a/www/board/agenda/views/buttons/attend.js.rb b/www/board/agenda/views/buttons/attend.js.rb
index 300af78..40da871 100644
--- a/www/board/agenda/views/buttons/attend.js.rb
+++ b/www/board/agenda/views/buttons/attend.js.rb
@@ -18,8 +18,7 @@ class Attend < Vue
     if person
       return person.attending
     else
-      for id in @@item.people
-        person = @@item.people[id]
+      @@item.people.each_pair do |id, person|
         return person.attending if person.name == User.username
       end
       return false
diff --git a/www/board/agenda/views/elements/additional-info.js.rb b/www/board/agenda/views/elements/additional-info.js.rb
index 7a04783..477a644 100644
--- a/www/board/agenda/views/elements/additional-info.js.rb
+++ b/www/board/agenda/views/elements/additional-info.js.rb
@@ -94,7 +94,7 @@ class AdditionalInfo < Vue
 
       # historical comments
       if history and not @prefix
-        for date in history
+        history.each_pair do |date, comments|
           next if Agenda.file == "board_agenda_#{date}.txt"
 
           _h5.history do
@@ -141,7 +141,7 @@ class AdditionalInfo < Vue
             end
           end
 
-          splitComments(history[date]).each do |comment|
+          splitComments(comments).each do |comment|
             _pre.comment do
               _Text raw: comment, filters: [hotlink]
             end
diff --git a/www/board/agenda/views/elements/pns.rb b/www/board/agenda/views/elements/pns.rb
index d37e760..81278c4 100644
--- a/www/board/agenda/views/elements/pns.rb
+++ b/www/board/agenda/views/elements/pns.rb
@@ -42,12 +42,8 @@ class PodlingNameSearch < Vue
     altname = props.item.fulltitle[/\((.*?)\)/, 1]
 
     if name and Server.podlingnamesearch
-      for podling in Server.podlingnamesearch
-        if name == podling
-          @results = Server.podlingnamesearch[name]
-        elsif altname == podling
-          @results = Server.podlingnamesearch[altname]
-        end
+      Server.podlingnamesearch.each_pair do |podling, jira|
+        @results = jira if name == podling or altname == podling
       end
     end
 
diff --git a/www/board/agenda/views/layout/main.js.rb b/www/board/agenda/views/layout/main.js.rb
index 1fb1b61..189b147 100644
--- a/www/board/agenda/views/layout/main.js.rb
+++ b/www/board/agenda/views/layout/main.js.rb
@@ -40,8 +40,8 @@ class Main < Vue
   # initial load of the agenda, and route first request
   def created()
     # copy server info for later use
-    for prop in @@server
-      Server[prop] = @@server[prop]
+    @@server.each_pair do |prop, value|
+      Server[prop] = value
     end
 
     Pending.fetch() if PageCache.enabled or not Server.userid
diff --git a/www/board/agenda/views/models/agenda.js.rb b/www/board/agenda/views/models/agenda.js.rb
index 00bbc11..3468ae2 100644
--- a/www/board/agenda/views/models/agenda.js.rb
+++ b/www/board/agenda/views/models/agenda.js.rb
@@ -143,8 +143,8 @@ class Agenda
   # initialize an entry by copying each JSON property to a class instance
   # variable.
   def initialize(entry)
-    for name in entry
-      self["_#{name}"] = entry[name]
+    entry.each_pair do |name, value|
+      self["_#{name}"] = value
     end
   end
 
diff --git a/www/board/agenda/views/models/chat.js.rb b/www/board/agenda/views/models/chat.js.rb
index 001519f..8efd793 100644
--- a/www/board/agenda/views/models/chat.js.rb
+++ b/www/board/agenda/views/models/chat.js.rb
@@ -138,16 +138,14 @@ class Chat
 
     # build an index of the 'before' drafts
     index = {}
-    for attach in before.drafts
-      item = before.drafts[attach]
+    before.drafts.each do |attach, item|
       index[item.project] = item
     end
 
     # categorize each item in the 'after' drafts
     add = []
     change = []
-    for attach in after.drafts
-      item = after.drafts[attach]
+    after.drafts.each_pair do |attach, item|
       before = index[item.project]
       console.log [before, item]
       if not before
diff --git a/www/board/agenda/views/models/minutes.js.rb b/www/board/agenda/views/models/minutes.js.rb
index 9abb609..a8ea2a2 100644
--- a/www/board/agenda/views/models/minutes.js.rb
+++ b/www/board/agenda/views/models/minutes.js.rb
@@ -15,8 +15,8 @@ class Minutes
   def self.actions
     actions = []
 
-    for title in @@list
-      minutes = @@list[title] + "\n\n"
+    @@list.each_pair do |title, minutes|
+      minutes += "\n\n"
       pattern = RegExp.new('^(?:@|AI\s+)(\w+):?\s+([\s\S]*?)(\n\n|$)', 'g')
       match = pattern.exec(minutes)
       while match
diff --git a/www/board/agenda/views/models/pending.js.rb b/www/board/agenda/views/models/pending.js.rb
index 099e6b8..8e585b1 100644
--- a/www/board/agenda/views/models/pending.js.rb
+++ b/www/board/agenda/views/models/pending.js.rb
@@ -96,8 +96,8 @@ class Pending
 
     Pending.status.each do |status|
       found = true
-      for name in action
-        found = false if name != 'status' and action[name] != status[name]
+      action.each_pair do |name, value|
+        found = false if name != 'status' and value != status[name]
       end
       match = status if found
     end
@@ -207,9 +207,8 @@ class Pending
       # apply offline changes
       Pending.dbget do |pending|
         if pending.approve
-          for attach in pending.approve
-            data = {attach: attach, request: pending.approve[attach]}
-            Pending.update('approve', data)
+          pending.approve.each_pair do |attach, request|
+            Pending.update('approve', attach: attach, request: request)
           end
         end
       end
diff --git a/www/board/agenda/views/pages/action-items.js.rb b/www/board/agenda/views/pages/action-items.js.rb
index ce23803..19ebcc4 100644
--- a/www/board/agenda/views/pages/action-items.js.rb
+++ b/www/board/agenda/views/pages/action-items.js.rb
@@ -18,8 +18,8 @@ class ActionItems < Vue
           # skip actions that don't match the filter
           if @@filter
             match = true
-            for key in @@filter
-              match &&= (action[key] == @@filter[key])
+            @@filter.each_pair do |key, filter|
+              match &&= (action[key] == filter)
             end
             next unless match
           end
@@ -76,8 +76,8 @@ class ActionItems < Vue
           options.attrs = {}
 
           # copy action properties to data attributes
-          for name in action
-            options.attrs["data-#{name}"] = action[name]
+          action.each_pair do |name, option|
+            options.attrs["data-#{name}"] = option
           end
 
           # include pending updates
@@ -138,8 +138,8 @@ class ActionItems < Vue
       Minutes.actions.each do |action|
         if @@filter
           match = true
-          for key in @@filter
-            match &&= (action[key] == @@filter[key])
+          @@filter.each_pair do |key, filter|
+            match &&= (action[key] == filter)
           end
           next unless match
         end
@@ -154,8 +154,8 @@ class ActionItems < Vue
             # skip actions that don't match the filter
             if @@filter
               match = true
-              for key in @@filter
-                match &&= (action[key] == @@filter[key])
+              @@filter.each_pair do |key, filter|
+                match &&= (action[key] == filter)
               end
               next unless match
             end
diff --git a/www/board/agenda/views/pages/adjournment.js.rb b/www/board/agenda/views/pages/adjournment.js.rb
index 578c44e..cbeb6b0 100644
--- a/www/board/agenda/views/pages/adjournment.js.rb
+++ b/www/board/agenda/views/pages/adjournment.js.rb
@@ -25,9 +25,9 @@ class Adjournment < Vue
   end
 
   # update state
-  def set(value)
-    for attr in value
-      Todos[attr] = value[attr]
+  def set(values)
+    values.each_pair do |attr, value|
+      Todos[attr] = value
     end
   end
 
@@ -296,8 +296,8 @@ class TodoRemove < Vue
     @disabled = true
 
     remove = []
-    for id in @checked
-      remove << id if @checked[id]
+    @checked.each_pair do |id, checked|
+      remove << id if checked
     end
 
     post "secretary-todos/#{Agenda.title}", remove: remove do |todos|
@@ -305,7 +305,7 @@ class TodoRemove < Vue
       Todos.set todos
 
       # uncheck people who were removed
-      for id in @checked
+      @checked.each_key do |id|
         unless Todos.remove.any? {|person| person.id == id}
           @checked[id] = false
         end
diff --git a/www/board/agenda/views/pages/fy23.js.rb b/www/board/agenda/views/pages/fy23.js.rb
index 038a081..2c3f97a 100644
--- a/www/board/agenda/views/pages/fy23.js.rb
+++ b/www/board/agenda/views/pages/fy23.js.rb
@@ -336,13 +336,13 @@ class FY23 < Vue
 
     if budget and budget != @budget and Minutes.started
 
-      for item in budget
+      budget.each_pair do |item, date|
         element = document.getElementById(item)
 
         if element.tagName == 'INPUT'
-          element.value = budget[item].toLocaleString()
+          element.value = date.toLocaleString()
         else
-          element.textContent = budget[item].toLocaleString()
+          element.textContent = date.toLocaleString()
         end
       end
 
diff --git a/www/board/agenda/views/pages/report.js.rb b/www/board/agenda/views/pages/report.js.rb
index 55e4aa9..f5b2a75 100644
--- a/www/board/agenda/views/pages/report.js.rb
+++ b/www/board/agenda/views/pages/report.js.rb
@@ -177,9 +177,7 @@ class Report < Vue
   def names(text)
     roster = '/roster/committer/'
 
-    for id in @@item.people
-      person = @@item.people[id]
-
+    @@item.people.each_pair do |id, person|
       # email addresses in 'Establish' resolutions and (ids) everywhere
       text.gsub! /(\(|&lt;)(#{id})( at |@|\))/ do |m, pre, id, post|
         if person.icla
diff --git a/www/board/agenda/views/pages/roll-call.js.rb b/www/board/agenda/views/pages/roll-call.js.rb
index 4837a4e..28f8372 100644
--- a/www/board/agenda/views/pages/roll-call.js.rb
+++ b/www/board/agenda/views/pages/roll-call.js.rb
@@ -72,8 +72,7 @@ class RollCall < Vue
     list = []
 
     # start with those listed in the agenda
-    for id in @@item.people
-      person = @@item.people[id]
+    @@item.people.each_pair do |id, person|
       person.id = id
       list << person
     end
@@ -81,9 +80,9 @@ class RollCall < Vue
     # add remaining attendees
     attendees = Minutes.attendees
     if attendees
-      for name in attendees
+      attendees.each_pair do |name, attendee|
         if not list.any? {|person| person.name == name}
-          person = attendees[name]
+          person = attendee
           person.name = name
           person.role = :guest
           list << person
diff --git a/www/board/agenda/views/pages/shepherd.js.rb b/www/board/agenda/views/pages/shepherd.js.rb
index f4bc312..f5ce095 100644
--- a/www/board/agenda/views/pages/shepherd.js.rb
+++ b/www/board/agenda/views/pages/shepherd.js.rb
@@ -47,12 +47,12 @@ class Shepherd < Vue
 
     # list feedback items that may need to be followed up
     followup = []
-    for title in @followup
-       next unless @followup[title].count == 1
-       next unless @followup[title].shepherd == @@item.shepherd
+    @followup.each_pair do |title, item|
+       next unless item.count == 1
+       next unless item.shepherd == @@item.shepherd
        next if Agenda.index.any? {|item| item.title == title}
-       @followup[title].title = title
-       followup << @followup[title]
+       item.title = title
+       followup << item
     end
 
     unless followup.empty?
diff --git a/www/board/agenda/views/router.js.rb b/www/board/agenda/views/router.js.rb
index 15cc195..9fbc4e9 100644
--- a/www/board/agenda/views/router.js.rb
+++ b/www/board/agenda/views/router.js.rb
@@ -145,13 +145,13 @@ class Router
         # form overrides
         form = button.form
         if form and form.button
-          for name in form.button
+          form.button.each_pair do |name, override|
             if name == 'text'
               props.text = form.button.text
             elsif name == 'class' or name == 'classname'
-              props.attrs.class += " #{form.button[name].gsub('_', '-')}"
+              props.attrs.class += " #{override.gsub('_', '-')}"
             else
-              props.attrs[name.gsub('_', '-')] = form.button[name]
+              props.attrs[name.gsub('_', '-')] = override
             end
           end
         else
@@ -162,13 +162,13 @@ class Router
         end
 
         # item overrides
-        for name in button
+        button.each_pair do |name, override|
           if name == 'text'
             props.text = button.text
           elsif name == 'class' or name == 'classname'
-            props.attrs.class += " #{button[name].gsub('_', '-')}"
+            props.attrs.class += " #{override.gsub('_', '-')}"
           elsif name != 'form'
-            props.attrs[name.gsub('_', '-')] = button[name]
+            props.attrs[name.gsub('_', '-')] = override
           end
         end
 


Mime
View raw message