Bug 1272452 - Use Immutable data structures in messages reducer. r=bgrins
authorNicolas Chevobbe <nch@atolcd.com>
Thu, 26 May 2016 10:17:08 -0700
changeset 299112 f24df446d3e345586d3165d24e5b3cb5f02534ea
parent 299111 2afb6c749a0811b00808ae098b193122af7a694e
child 299113 d495fe0a0cb21d80da64bd3d2c3e8b44e582ecb3
push id30290
push userryanvm@gmail.com
push dateFri, 27 May 2016 01:44:20 +0000
treeherdermozilla-central@34ac60e5b29c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1272452
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1272452 - Use Immutable data structures in messages reducer. r=bgrins MozReview-Commit-ID: 8k8qsIi3IrD
devtools/client/webconsole/new-console-output/reducers/messages.js
devtools/client/webconsole/new-console-output/test/store/test_messages.js
--- a/devtools/client/webconsole/new-console-output/reducers/messages.js
+++ b/devtools/client/webconsole/new-console-output/reducers/messages.js
@@ -1,29 +1,30 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
+const Immutable = require("devtools/client/shared/vendor/immutable");
 const constants = require("devtools/client/webconsole/new-console-output/constants");
 
-function messages(state = [], action) {
+function messages(state = Immutable.List(), action) {
   switch (action.type) {
     case constants.MESSAGE_ADD:
       let newMessage = action.message;
-      if (newMessage.allowRepeating && state.length > 0) {
-        let lastMessage = state[state.length - 1];
+      if (newMessage.allowRepeating && state.size > 0) {
+        let lastMessage = state.last();
         if (lastMessage.repeatId === newMessage.repeatId) {
           newMessage.repeat = lastMessage.repeat + 1;
-          return state.slice(0, state.length - 1).concat(newMessage);
+          return state.pop().push(newMessage);
         }
       }
-      return state.concat([ newMessage ]);
+      return state.push(newMessage);
     case constants.MESSAGES_CLEAR:
-      return [];
+      return Immutable.List();
   }
 
   return state;
 }
 
 exports.messages = messages;
--- a/devtools/client/webconsole/new-console-output/test/store/test_messages.js
+++ b/devtools/client/webconsole/new-console-output/test/store/test_messages.js
@@ -19,35 +19,37 @@ function run_test() {
  */
 add_task(function* () {
   const { getState, dispatch } = storeFactory();
 
   dispatch(actions.messageAdd(packet));
 
   const expectedMessage = prepareMessage(packet);
 
-  deepEqual(getAllMessages(getState()), [expectedMessage],
+  let messages = getAllMessages(getState());
+  deepEqual(messages.toArray(), [expectedMessage],
     "MESSAGE_ADD action adds a message");
 });
 
 /**
  * Test repeating messages in the store.
  */
 add_task(function* () {
   const { getState, dispatch } = storeFactory();
 
   dispatch(actions.messageAdd(packet));
   dispatch(actions.messageAdd(packet));
   dispatch(actions.messageAdd(packet));
 
   const expectedMessage = prepareMessage(packet);
   expectedMessage.repeat = 3;
 
-  deepEqual(getAllMessages(getState()), [expectedMessage],
-    "Adding same message to the store twice results in repeated message");
+  let messages = getAllMessages(getState());
+  deepEqual(messages.toArray(), [expectedMessage],
+    "Adding same message to the store three times results in repeated message");
 });
 
 /**
  * Test getRepeatId().
  */
 add_task(function* () {
   const message1 = prepareMessage(packet);
   const message2 = prepareMessage(packet);