Update behavior format for template type safety check

In order to get type safety check working, behaviors needed to be
refactored so that the behavior assignment contains the actual
behavior object, rather than a reference to the object. This is done
so that the behaviors can easily be passed to fried-twinkie as
additional source files.

Feature: Issue 6914
Change-Id: Ibc4c5b6e2f53498f822be2df5aa41514831e6f5f
diff --git a/polygerrit-ui/app/behaviors/base-url-behavior/base-url-behavior.html b/polygerrit-ui/app/behaviors/base-url-behavior/base-url-behavior.html
index 2174fc6..fce06c9 100644
--- a/polygerrit-ui/app/behaviors/base-url-behavior/base-url-behavior.html
+++ b/polygerrit-ui/app/behaviors/base-url-behavior/base-url-behavior.html
@@ -18,8 +18,10 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.BaseUrlBehavior */
-  const BaseUrlBehavior = {
+  Gerrit.BaseUrlBehavior = {
     getBaseUrl() {
       return window.CANONICAL_PATH || '';
     },
@@ -30,8 +32,5 @@
       return base + '/?polygerrit=0#' + clientPath;
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.BaseUrlBehavior = BaseUrlBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/docs-url-behavior/docs-url-behavior.html b/polygerrit-ui/app/behaviors/docs-url-behavior/docs-url-behavior.html
index 4074c3b..394ec74 100644
--- a/polygerrit-ui/app/behaviors/docs-url-behavior/docs-url-behavior.html
+++ b/polygerrit-ui/app/behaviors/docs-url-behavior/docs-url-behavior.html
@@ -23,8 +23,10 @@
 
   let cachedPromise;
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.DocsUrlBehavior */
-  const DocsUrlBehavior = {
+  Gerrit.DocsUrlBehavior = [{
 
     /**
      * Get the docs base URL from either the server config or by probing.
@@ -52,12 +54,8 @@
     _clearDocsBaseUrlCache() {
       cachedPromise = undefined;
     },
-  };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.DocsUrlBehavior = [
-    window.Gerrit.BaseUrlBehavior,
-    DocsUrlBehavior,
+  },
+    Gerrit.BaseUrlBehavior,
   ];
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-anonymous-name-behavior/gr-anonymous-name-behavior.html b/polygerrit-ui/app/behaviors/gr-anonymous-name-behavior/gr-anonymous-name-behavior.html
index 9fd7f10..329611f 100644
--- a/polygerrit-ui/app/behaviors/gr-anonymous-name-behavior/gr-anonymous-name-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-anonymous-name-behavior/gr-anonymous-name-behavior.html
@@ -20,8 +20,10 @@
 
   const ANONYMOUS_NAME = 'Anonymous';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.AnonymousNameBehavior */
-  const AnonymousNameBehavior = {
+  Gerrit.AnonymousNameBehavior = {
     getAnonymousName(config) {
       if (config && config.user &&
           config.user.anonymous_coward_name !== 'Anonymous Coward') {
@@ -31,8 +33,5 @@
       return ANONYMOUS_NAME;
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.AnonymousNameBehavior = AnonymousNameBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.html b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.html
index 178dd7c..af266b4 100644
--- a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.html
@@ -17,8 +17,10 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.ChangeTableBehavior */
-  const ChangeTableBehavior = {
+  Gerrit.ChangeTableBehavior = {
     properties: {
       columnNames: {
         type: Array,
@@ -49,8 +51,5 @@
       return !columnsToDisplay.includes(columnToCheck);
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.ChangeTableBehavior = ChangeTableBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-list-view-behavior/gr-list-view-behavior.html b/polygerrit-ui/app/behaviors/gr-list-view-behavior/gr-list-view-behavior.html
index c6fc7e3..98749be 100644
--- a/polygerrit-ui/app/behaviors/gr-list-view-behavior/gr-list-view-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-list-view-behavior/gr-list-view-behavior.html
@@ -19,8 +19,10 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.ListViewBehavior */
-  const ListViewBehavior = {
+  Gerrit.ListViewBehavior = [{
     computeLoadingClass(loading) {
       return loading ? 'loading' : '';
     },
@@ -44,12 +46,9 @@
       }
       return 0;
     },
-  };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.ListViewBehavior = [
-    ListViewBehavior,
-    window.Gerrit.BaseUrlBehavior,
-    window.Gerrit.URLEncodingBehavior];
+  },
+    Gerrit.BaseUrlBehavior,
+    Gerrit.URLEncodingBehavior,
+  ];
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html b/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html
index faf1489..74e2ee4 100644
--- a/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html
@@ -28,9 +28,10 @@
     'autogenerated:gerrit:setReadyForReview',
   ];
 
-  /** @polymerBehavior Gerrit.PatchSetBehavior */
-  const PatchSetBehavior = {
-    // Corresponds to the patchNum for an edit patchset.
+  window.Gerrit = window.Gerrit || {};
+
+  /** @polymerBehavior this */
+  Gerrit.PatchSetBehavior = {
     EDIT_NAME: 'edit',
 
     /**
@@ -53,7 +54,7 @@
      */
     getRevisionByPatchNum(revisions, patchNum) {
       for (const rev of Object.values(revisions || {})) {
-        if (PatchSetBehavior.patchNumEquals(rev._number, patchNum)) {
+        if (Gerrit.PatchSetBehavior.patchNumEquals(rev._number, patchNum)) {
           return rev;
         }
       }
@@ -68,7 +69,8 @@
      */
     findEditParentRevision(revisions) {
       const editInfo =
-          revisions.find(info => info._number === PatchSetBehavior.EDIT_NAME);
+          revisions.find(info => info._number ===
+              Gerrit.PatchSetBehavior.EDIT_NAME);
 
       if (!editInfo) { return null; }
 
@@ -83,7 +85,8 @@
      * @return {number} Change edit patch set number or -1.
      */
     findEditParentPatchNum(revisions) {
-      const revisionInfo = PatchSetBehavior.findEditParentRevision(revisions);
+      const revisionInfo =
+          Gerrit.PatchSetBehavior.findEditParentRevision(revisions);
       return revisionInfo ? revisionInfo._number : -1;
     },
 
@@ -98,11 +101,12 @@
      * @return {!Array<!Object>} The sorted {revisions} array
      */
     sortRevisions(revisions) {
-      const editParent = PatchSetBehavior.findEditParentPatchNum(revisions);
+      const editParent =
+          Gerrit.PatchSetBehavior.findEditParentPatchNum(revisions);
       // Map a normal patchNum to 2 * (patchNum - 1) + 1... I.e. 1 -> 1,
       // 2 -> 3, 3 -> 5, etc.
       // Map an edit to the patchNum of parent*2... I.e. edit on 2 -> 4.
-      const num = r => r._number === PatchSetBehavior.EDIT_NAME ?
+      const num = r => r._number === Gerrit.PatchSetBehavior.EDIT_NAME ?
           2 * editParent :
           2 * (r._number - 1) + 1;
       return revisions.sort((a, b) => num(a) - num(b));
@@ -129,7 +133,7 @@
       if (change.revisions &&
           Object.keys(change.revisions).length) {
         patchNums =
-          PatchSetBehavior.sortRevisions(Object.values(change.revisions))
+          Gerrit.PatchSetBehavior.sortRevisions(Object.values(change.revisions))
               .map(e => {
                 // TODO(kaspern): Mark which patchset an edit was made on, if an
                 // edit exists -- perhaps with a temporary description.
@@ -139,8 +143,8 @@
                 };
               });
       }
-      patchNums.sort((a, b) => a.num - b.num);
-      return PatchSetBehavior._computeWipForPatchSets(change, patchNums);
+      patchNums.sort((a, b) => { return a.num - b.num; });
+      return Gerrit.PatchSetBehavior._computeWipForPatchSets(change, patchNums);
     },
 
     /**
@@ -179,7 +183,7 @@
     computeLatestPatchNum(allPatchSets) {
       if (!allPatchSets || !allPatchSets.length) { return undefined; }
       if (allPatchSets[allPatchSets.length - 1].num ===
-          PatchSetBehavior.EDIT_NAME) {
+          Gerrit.PatchSetBehavior.EDIT_NAME) {
         return allPatchSets[allPatchSets.length - 2].num;
       }
       return allPatchSets[allPatchSets.length - 1].num;
@@ -194,15 +198,15 @@
      *     meantime. The promise is rejected on network error.
      */
     fetchIsLatestKnown(change, restAPI) {
-      const knownLatest = PatchSetBehavior.computeLatestPatchNum(
-          PatchSetBehavior.computeAllPatchSets(change));
+      const knownLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
+          Gerrit.PatchSetBehavior.computeAllPatchSets(change));
       return restAPI.getChangeDetail(change._number)
           .then(detail => {
             if (!detail) {
               return Promise.reject('Unable to check for latest patchset.');
             }
-            const actualLatest = PatchSetBehavior.computeLatestPatchNum(
-                PatchSetBehavior.computeAllPatchSets(detail));
+            const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
+                Gerrit.PatchSetBehavior.computeAllPatchSets(detail));
             return actualLatest <= knownLatest;
           });
     },
@@ -219,8 +223,5 @@
       return revisions.findIndex(findNum);
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.PatchSetBehavior = PatchSetBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-path-list-behavior/gr-path-list-behavior.html b/polygerrit-ui/app/behaviors/gr-path-list-behavior/gr-path-list-behavior.html
index 2ccae2c..0d4e7f1 100644
--- a/polygerrit-ui/app/behaviors/gr-path-list-behavior/gr-path-list-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-path-list-behavior/gr-path-list-behavior.html
@@ -17,8 +17,9 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
   /** @polymerBehavior Gerrit.PathListBehavior */
-  const PathListBehavior = {
+  Gerrit.PathListBehavior = {
     specialFilePathCompare(a, b) {
       // The commit message always goes first.
       const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
@@ -62,8 +63,5 @@
       return aFile.localeCompare(bFile) || a.localeCompare(b);
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.PathListBehavior = PathListBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
index 54a59ca..0cc3466 100644
--- a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
+++ b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
@@ -16,8 +16,10 @@
 
   const BOTTOM_OFFSET = 7.2; // Height of the arrow in tooltip.
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.TooltipBehavior */
-  const TooltipBehavior = {
+  Gerrit.TooltipBehavior = {
 
     properties: {
       hasTooltip: {
@@ -125,7 +127,4 @@
           'px))';
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.TooltipBehavior = TooltipBehavior;
 })(window);
diff --git a/polygerrit-ui/app/behaviors/gr-url-encoding-behavior.html b/polygerrit-ui/app/behaviors/gr-url-encoding-behavior.html
index 25d9c27..99c7c16 100644
--- a/polygerrit-ui/app/behaviors/gr-url-encoding-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-url-encoding-behavior.html
@@ -17,8 +17,10 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.URLEncodingBehavior */
-  const URLEncodingBehavior = {
+  Gerrit.URLEncodingBehavior = {
     /**
      * Pretty-encodes a URL. Double-encodes the string, and then replaces
      *   benevolent characters for legibility.
@@ -35,8 +37,5 @@
       return output;
     },
   };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.URLEncodingBehavior = URLEncodingBehavior;
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
index 8ce43b3..9c414fc4 100644
--- a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
+++ b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
@@ -29,8 +29,10 @@
     return e;
   };
 
-  /** @polymerBehavior KeyboardShortcutBehaviorImpl */
-  const KeyboardShortcutBehaviorImpl = {
+  window.Gerrit = window.Gerrit || {};
+
+  /** @polymerBehavior KeyboardShortcutBehavior */
+  Gerrit.KeyboardShortcutBehavior = [{
     modifierPressed(e) {
       e = getKeyboardEvent(e);
       return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
@@ -60,13 +62,8 @@
     getRootTarget(e) {
       return Polymer.dom(getKeyboardEvent(e)).rootTarget;
     },
-  };
-
-  window.Gerrit = window.Gerrit || {};
-  /** @polymerBehavior Gerrit.KeyboardShortcutBehavior */
-  window.Gerrit.KeyboardShortcutBehavior = [
+  },
     Polymer.IronA11yKeysBehavior,
-    KeyboardShortcutBehaviorImpl,
   ];
 })(window);
 </script>
diff --git a/polygerrit-ui/app/behaviors/rest-client-behavior/rest-client-behavior.html b/polygerrit-ui/app/behaviors/rest-client-behavior/rest-client-behavior.html
index a9adbcb..f5e17c9 100644
--- a/polygerrit-ui/app/behaviors/rest-client-behavior/rest-client-behavior.html
+++ b/polygerrit-ui/app/behaviors/rest-client-behavior/rest-client-behavior.html
@@ -19,8 +19,10 @@
 (function(window) {
   'use strict';
 
+  window.Gerrit = window.Gerrit || {};
+
   /** @polymerBehavior Gerrit.RESTClientBehavior */
-  const RESTClientBehavior = {
+  Gerrit.RESTClientBehavior = [{
     ChangeDiffType: {
       ADDED: 'ADDED',
       COPIED: 'COPIED',
@@ -131,12 +133,8 @@
       if (change.status === this.ChangeStatus.DRAFT) { states.push('Draft'); }
       return states.join(', ');
     },
-  };
-
-  window.Gerrit = window.Gerrit || {};
-  window.Gerrit.RESTClientBehavior = [
+  },
     Gerrit.BaseUrlBehavior,
-    RESTClientBehavior,
   ];
 })(window);
 </script>