From 97062ecc32d7003a9707d401a8aa16e4420e750e Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Wed, 19 Nov 2014 14:59:08 +0000 Subject: [PATCH] Bug 1094137 - Create a common shared store creator for Loop. r=Standard8 --- .../components/loop/content/conversation.html | 3 +- .../loop/content/js/conversation.js | 6 +- .../loop/content/js/conversation.jsx | 6 +- browser/components/loop/content/js/panel.js | 5 +- browser/components/loop/content/js/panel.jsx | 5 +- .../components/loop/content/js/roomViews.js | 2 +- .../components/loop/content/js/roomViews.jsx | 2 +- browser/components/loop/content/panel.html | 1 + .../loop/content/shared/js/actions.js | 2 + .../loop/content/shared/js/activeRoomStore.js | 144 ++++++---------- .../content/shared/js/conversationStore.js | 1 + .../loop/content/shared/js/roomStore.js | 153 +++++------------ .../loop/content/shared/js/store.js | 96 +++++++++++ browser/components/loop/jar.mn | 1 + .../loop/standalone/content/index.html | 3 +- .../loop/standalone/content/js/webapp.js | 3 +- .../loop/standalone/content/js/webapp.jsx | 3 +- .../test/desktop-local/conversation_test.js | 3 +- .../loop/test/desktop-local/index.html | 1 + .../loop/test/desktop-local/panel_test.js | 6 +- .../loop/test/desktop-local/roomViews_test.js | 6 +- .../loop/test/shared/activeRoomStore_test.js | 17 +- .../components/loop/test/shared/index.html | 4 +- .../loop/test/shared/roomStore_test.js | 42 +---- .../components/loop/test/shared/store_test.js | 160 ++++++++++++++++++ .../loop/test/standalone/index.html | 1 + .../standalone/standaloneRoomViews_test.js | 3 +- .../loop/test/standalone/webapp_test.js | 3 +- browser/components/loop/ui/index.html | 3 +- browser/components/loop/ui/ui-showcase.js | 6 +- browser/components/loop/ui/ui-showcase.jsx | 6 +- 31 files changed, 408 insertions(+), 289 deletions(-) create mode 100644 browser/components/loop/content/shared/js/store.js create mode 100644 browser/components/loop/test/shared/store_test.js diff --git a/browser/components/loop/content/conversation.html b/browser/components/loop/content/conversation.html index 730ddb3a4675..3f9145c9971d 100644 --- a/browser/components/loop/content/conversation.html +++ b/browser/components/loop/content/conversation.html @@ -34,8 +34,9 @@ - + + diff --git a/browser/components/loop/content/js/conversation.js b/browser/components/loop/content/js/conversation.js index 90ca19b7e48d..73afcb5b8b2d 100644 --- a/browser/components/loop/content/js/conversation.js +++ b/browser/components/loop/content/js/conversation.js @@ -641,13 +641,11 @@ loop.conversation = (function(mozL10n) { dispatcher: dispatcher, sdkDriver: sdkDriver }); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: navigator.mozLoop, sdkDriver: sdkDriver }); - var roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + var roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop, activeRoomStore: activeRoomStore }); diff --git a/browser/components/loop/content/js/conversation.jsx b/browser/components/loop/content/js/conversation.jsx index a887ddd193e5..7d6e0ce7248b 100644 --- a/browser/components/loop/content/js/conversation.jsx +++ b/browser/components/loop/content/js/conversation.jsx @@ -641,13 +641,11 @@ loop.conversation = (function(mozL10n) { dispatcher: dispatcher, sdkDriver: sdkDriver }); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: navigator.mozLoop, sdkDriver: sdkDriver }); - var roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + var roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop, activeRoomStore: activeRoomStore }); diff --git a/browser/components/loop/content/js/panel.js b/browser/components/loop/content/js/panel.js index c29a0721a00e..3a76a6d23695 100644 --- a/browser/components/loop/content/js/panel.js +++ b/browser/components/loop/content/js/panel.js @@ -845,9 +845,8 @@ loop.panel = (function(_, mozL10n) { var client = new loop.Client(); var notifications = new sharedModels.NotificationCollection(); var dispatcher = new loop.Dispatcher(); - var roomStore = new loop.store.RoomStore({ - mozLoop: navigator.mozLoop, - dispatcher: dispatcher + var roomStore = new loop.store.RoomStore(dispatcher, { + mozLoop: navigator.mozLoop }); React.renderComponent(PanelView({ diff --git a/browser/components/loop/content/js/panel.jsx b/browser/components/loop/content/js/panel.jsx index 3f25d5bfa1cf..3e5e501c9387 100644 --- a/browser/components/loop/content/js/panel.jsx +++ b/browser/components/loop/content/js/panel.jsx @@ -845,9 +845,8 @@ loop.panel = (function(_, mozL10n) { var client = new loop.Client(); var notifications = new sharedModels.NotificationCollection(); var dispatcher = new loop.Dispatcher(); - var roomStore = new loop.store.RoomStore({ - mozLoop: navigator.mozLoop, - dispatcher: dispatcher + var roomStore = new loop.store.RoomStore(dispatcher, { + mozLoop: navigator.mozLoop }); React.renderComponent( + diff --git a/browser/components/loop/content/shared/js/actions.js b/browser/components/loop/content/shared/js/actions.js index 9cf523941e36..c4d5234d57a2 100644 --- a/browser/components/loop/content/shared/js/actions.js +++ b/browser/components/loop/content/shared/js/actions.js @@ -30,6 +30,8 @@ loop.shared.actions = (function() { }; return { + Action: Action, + /** * Get the window data for the provided window id */ diff --git a/browser/components/loop/content/shared/js/activeRoomStore.js b/browser/components/loop/content/shared/js/activeRoomStore.js index 9a7b16dec2f5..dea831655a6d 100644 --- a/browser/components/loop/content/shared/js/activeRoomStore.js +++ b/browser/components/loop/content/shared/js/activeRoomStore.js @@ -6,6 +6,7 @@ var loop = loop || {}; loop.store = loop.store || {}; + loop.store.ActiveRoomStore = (function() { "use strict"; @@ -40,80 +41,52 @@ loop.store.ActiveRoomStore = (function() { }; /** - * Store for things that are local to this instance (in this profile, on - * this machine) of this roomRoom store, in addition to a mirror of some - * remote-state. + * Active room store. * - * @extends {Backbone.Events} - * - * @param {Object} options - Options object - * @param {loop.Dispatcher} options.dispatch - The dispatcher for dispatching - * actions and registering to consume them. - * @param {MozLoop} options.mozLoop - MozLoop API provider object + * @param {loop.Dispatcher} dispatcher The dispatcher for dispatching actions + * and registering to consume actions. + * @param {Object} options Options object: + * - {mozLoop} mozLoop The MozLoop API object. + * - {OTSdkDriver} sdkDriver The SDK driver instance. */ - function ActiveRoomStore(options) { - options = options || {}; - - if (!options.dispatcher) { - throw new Error("Missing option dispatcher"); - } - this._dispatcher = options.dispatcher; - - if (!options.mozLoop) { - throw new Error("Missing option mozLoop"); - } - this._mozLoop = options.mozLoop; - - if (!options.sdkDriver) { - throw new Error("Missing option sdkDriver"); - } - this._sdkDriver = options.sdkDriver; - - // XXX Further actions are registered in setupWindowData and - // fetchServerData when we know what window type this is. At some stage, - // we might want to consider store mixins or some alternative which - // means the stores would only be created when we want them. - this._dispatcher.register(this, [ - "setupWindowData", - "fetchServerData" - ]); - - /** - * Stored data reflecting the local state of a given room, used to drive - * the room's views. - * - * @see https://wiki.mozilla.org/Loop/Architecture/Rooms#GET_.2Frooms.2F.7Btoken.7D - * for the main data. Additional properties below. - * - * @property {ROOM_STATES} roomState - the state of the room. - * @property {Error=} error - if the room is an error state, this will be - * set to an Error object reflecting the problem; - * otherwise it will be unset. - */ - this._storeState = { - roomState: ROOM_STATES.INIT, - audioMuted: false, - videoMuted: false, - failureReason: undefined - }; - } - - ActiveRoomStore.prototype = _.extend({ + var ActiveRoomStore = loop.store.createStore({ /** * The time factor to adjust the expires time to ensure that we send a refresh * before the expiry. Currently set as 90%. */ expiresTimeFactor: 0.9, - getStoreState: function() { - return this._storeState; + // XXX Further actions are registered in setupWindowData and + // fetchServerData when we know what window type this is. At some stage, + // we might want to consider store mixins or some alternative which + // means the stores would only be created when we want them. + actions: [ + "setupWindowData", + "fetchServerData" + ], + + initialize: function(options) { + if (!options.mozLoop) { + throw new Error("Missing option mozLoop"); + } + this._mozLoop = options.mozLoop; + + if (!options.sdkDriver) { + throw new Error("Missing option sdkDriver"); + } + this._sdkDriver = options.sdkDriver; }, - setStoreState: function(newState) { - for (var key in newState) { - this._storeState[key] = newState[key]; - } - this.trigger("change"); + /** + * Returns initial state data for this active room. + */ + getInitialStoreState: function() { + return { + roomState: ROOM_STATES.INIT, + audioMuted: false, + videoMuted: false, + failureReason: undefined + }; }, /** @@ -145,10 +118,10 @@ loop.store.ActiveRoomStore = (function() { /** * Registers the actions with the dispatcher that this store is interested - * in. + * in after the initial setup has been performed. */ - _registerActions: function() { - this._dispatcher.register(this, [ + _registerPostSetupActions: function() { + this.dispatcher.register(this, [ "roomFailure", "setupRoomInfo", "updateRoomInfo", @@ -178,7 +151,7 @@ loop.store.ActiveRoomStore = (function() { return; } - this._registerActions(); + this._registerPostSetupActions(); this.setStoreState({ roomState: ROOM_STATES.GATHER @@ -188,23 +161,20 @@ loop.store.ActiveRoomStore = (function() { this._mozLoop.rooms.get(actionData.roomToken, function(error, roomData) { if (error) { - this._dispatcher.dispatch(new sharedActions.RoomFailure({ - error: error - })); + this.dispatchAction(new sharedActions.RoomFailure({error: error})); return; } - this._dispatcher.dispatch( - new sharedActions.SetupRoomInfo({ - roomToken: actionData.roomToken, - roomName: roomData.roomName, - roomOwner: roomData.roomOwner, - roomUrl: roomData.roomUrl - })); + this.dispatchAction(new sharedActions.SetupRoomInfo({ + roomToken: actionData.roomToken, + roomName: roomData.roomName, + roomOwner: roomData.roomOwner, + roomUrl: roomData.roomUrl + })); // For the conversation window, we need to automatically // join the room. - this._dispatcher.dispatch(new sharedActions.JoinRoom()); + this.dispatchAction(new sharedActions.JoinRoom()); }.bind(this)); }, @@ -222,7 +192,7 @@ loop.store.ActiveRoomStore = (function() { return; } - this._registerActions(); + this._registerPostSetupActions(); this.setStoreState({ roomToken: actionData.token, @@ -272,7 +242,7 @@ loop.store.ActiveRoomStore = (function() { * @param {Object} roomData The new roomData. */ _handleRoomUpdate: function(eventName, roomData) { - this._dispatcher.dispatch(new sharedActions.UpdateRoomInfo({ + this.dispatchAction(new sharedActions.UpdateRoomInfo({ roomName: roomData.roomName, roomOwner: roomData.roomOwner, roomUrl: roomData.roomUrl @@ -291,12 +261,11 @@ loop.store.ActiveRoomStore = (function() { this._mozLoop.rooms.join(this._storeState.roomToken, function(error, responseData) { if (error) { - this._dispatcher.dispatch( - new sharedActions.RoomFailure({error: error})); + this.dispatchAction(new sharedActions.RoomFailure({error: error})); return; } - this._dispatcher.dispatch(new sharedActions.JoinedRoom({ + this.dispatchAction(new sharedActions.JoinedRoom({ apiKey: responseData.apiKey, sessionToken: responseData.sessionToken, sessionId: responseData.sessionId, @@ -420,8 +389,7 @@ loop.store.ActiveRoomStore = (function() { this._storeState.sessionToken, function(error, responseData) { if (error) { - this._dispatcher.dispatch( - new sharedActions.RoomFailure({error: error})); + this.dispatchAction(new sharedActions.RoomFailure({error: error})); return; } @@ -459,9 +427,7 @@ loop.store.ActiveRoomStore = (function() { roomState: nextState ? nextState : ROOM_STATES.READY }); } - - }, Backbone.Events); + }); return ActiveRoomStore; - })(); diff --git a/browser/components/loop/content/shared/js/conversationStore.js b/browser/components/loop/content/shared/js/conversationStore.js index aabd2fa4d69e..d039d518f126 100644 --- a/browser/components/loop/content/shared/js/conversationStore.js +++ b/browser/components/loop/content/shared/js/conversationStore.js @@ -53,6 +53,7 @@ loop.store.ConversationStore = (function() { TERMINATED: "cs-terminated" }; + // XXX this needs to migrate to use loop.store.createStore var ConversationStore = Backbone.Model.extend({ defaults: { // The id of the window. Currently used for getting the window id. diff --git a/browser/components/loop/content/shared/js/roomStore.js b/browser/components/loop/content/shared/js/roomStore.js index 06ea478ff988..e324784ae273 100644 --- a/browser/components/loop/content/shared/js/roomStore.js +++ b/browser/components/loop/content/shared/js/roomStore.js @@ -47,52 +47,14 @@ loop.store = loop.store || {}; /** * Room store. * - * Options: - * - {loop.Dispatcher} dispatcher The dispatcher for dispatching actions + * @param {loop.Dispatcher} dispatcher The dispatcher for dispatching actions * and registering to consume actions. + * @param {Object} options Options object: * - {mozLoop} mozLoop The MozLoop API object. * - {ActiveRoomStore} activeRoomStore An optional substore for active room * state. - * - * @extends {Backbone.Events} - * @param {Object} options Options object. */ - function RoomStore(options) { - options = options || {}; - - if (!options.dispatcher) { - throw new Error("Missing option dispatcher"); - } - this._dispatcher = options.dispatcher; - - if (!options.mozLoop) { - throw new Error("Missing option mozLoop"); - } - this._mozLoop = options.mozLoop; - - if (options.activeRoomStore) { - this.activeRoomStore = options.activeRoomStore; - this.setStoreState({activeRoom: this.activeRoomStore.getStoreState()}); - this.activeRoomStore.on("change", - this._onActiveRoomStoreChange.bind(this)); - } - - this._dispatcher.register(this, [ - "createRoom", - "createRoomError", - "copyRoomUrl", - "deleteRoom", - "deleteRoomError", - "emailRoomUrl", - "getAllRooms", - "getAllRoomsError", - "openRoom", - "renameRoom", - "updateRoomList" - ]); - } - - RoomStore.prototype = _.extend({ + loop.store.RoomStore = loop.store.createStore({ /** * Maximum size given to createRoom; only 2 is supported (and is * always passed) because that's what the user-experience is currently @@ -108,58 +70,44 @@ loop.store = loop.store || {}; defaultExpiresIn: 24 * 7 * 8, /** - * Internal store state representation. - * @type {Object} - * @see #getStoreState + * Registered actions. + * @type {Array} */ - _storeState: { - activeRoom: {}, - error: null, - pendingCreation: false, - pendingInitialRetrieval: false, - rooms: [] + actions: [ + "createRoom", + "createRoomError", + "copyRoomUrl", + "deleteRoom", + "deleteRoomError", + "emailRoomUrl", + "getAllRooms", + "getAllRoomsError", + "openRoom", + "renameRoom", + "updateRoomList" + ], + + initialize: function(options) { + if (!options.mozLoop) { + throw new Error("Missing option mozLoop"); + } + this._mozLoop = options.mozLoop; + + if (options.activeRoomStore) { + this.activeRoomStore = options.activeRoomStore; + this.activeRoomStore.on("change", + this._onActiveRoomStoreChange.bind(this)); + } }, - /** - * Retrieves current store state. The returned state object holds the - * following properties: - * - * - {Boolean} pendingCreation Pending room creation flag. - * - {Boolean} pendingInitialRetrieval Pending initial list retrieval flag. - * - {Array} rooms The current room list. - * - {Error} error Latest error encountered, if any. - * - {Object} activeRoom Active room data, if any. - * - * You can request a given state property by providing the `key` argument. - * - * @param {String|undefined} key An optional state property name. - * @return {Object} - */ - getStoreState: function(key) { - if (key) { - return this._storeState[key]; - } - return this._storeState; - }, - - /** - * Updates store state and trigger a global "change" event, plus one for - * each provided newState property: - * - * - change:rooms - * - change:pendingInitialRetrieval - * - change:pendingCreation - * - change:error - * - change:activeRoom - * - * @param {Object} newState The new store state object. - */ - setStoreState: function(newState) { - for (var key in newState) { - this._storeState[key] = newState[key]; - this.trigger("change:" + key); - } - this.trigger("change"); + getInitialStoreState: function() { + return { + activeRoom: this.activeRoomStore ? this.activeRoomStore.getStoreState() : {}, + error: null, + pendingCreation: false, + pendingInitialRetrieval: false, + rooms: [] + }; }, /** @@ -179,15 +127,6 @@ loop.store = loop.store || {}; this.setStoreState({activeRoom: this.activeRoomStore.getStoreState()}); }, - /** - * Local proxy helper to dispatch an action. - * - * @param {Action} action The action to dispatch. - */ - _dispatchAction: function(action) { - this._dispatcher.dispatch(action); - }, - /** * Updates current room list when a new room is available. * @@ -197,7 +136,7 @@ loop.store = loop.store || {}; _onRoomAdded: function(eventName, addedRoomData) { addedRoomData.participants = []; addedRoomData.ctime = new Date().getTime(); - this._dispatchAction(new sharedActions.UpdateRoomList({ + this.dispatchAction(new sharedActions.UpdateRoomList({ roomList: this._storeState.rooms.concat(new Room(addedRoomData)) })); }, @@ -209,7 +148,7 @@ loop.store = loop.store || {}; * @param {Object} updatedRoomData The updated room data. */ _onRoomUpdated: function(eventName, updatedRoomData) { - this._dispatchAction(new sharedActions.UpdateRoomList({ + this.dispatchAction(new sharedActions.UpdateRoomList({ roomList: this._storeState.rooms.map(function(room) { return room.roomToken === updatedRoomData.roomToken ? updatedRoomData : room; @@ -224,7 +163,7 @@ loop.store = loop.store || {}; * @param {Object} removedRoomData The removed room data. */ _onRoomRemoved: function(eventName, removedRoomData) { - this._dispatchAction(new sharedActions.UpdateRoomList({ + this.dispatchAction(new sharedActions.UpdateRoomList({ roomList: this._storeState.rooms.filter(function(room) { return room.roomToken !== removedRoomData.roomToken; }) @@ -303,7 +242,7 @@ loop.store = loop.store || {}; this._mozLoop.rooms.create(roomCreationData, function(err) { this.setStoreState({pendingCreation: false}); if (err) { - this._dispatchAction(new sharedActions.CreateRoomError({error: err})); + this.dispatchAction(new sharedActions.CreateRoomError({error: err})); } }.bind(this)); }, @@ -346,7 +285,7 @@ loop.store = loop.store || {}; deleteRoom: function(actionData) { this._mozLoop.rooms.delete(actionData.roomToken, function(err) { if (err) { - this._dispatchAction(new sharedActions.DeleteRoomError({error: err})); + this.dispatchAction(new sharedActions.DeleteRoomError({error: err})); } }.bind(this)); }, @@ -376,7 +315,7 @@ loop.store = loop.store || {}; action = new sharedActions.UpdateRoomList({roomList: rawRoomList}); } - this._dispatchAction(action); + this.dispatchAction(action); // We can only start listening to room events after getAll() has been // called executed first. @@ -428,7 +367,5 @@ loop.store = loop.store || {}; } }); } - }, Backbone.Events); - - loop.store.RoomStore = RoomStore; + }); })(); diff --git a/browser/components/loop/content/shared/js/store.js b/browser/components/loop/content/shared/js/store.js new file mode 100644 index 000000000000..1b6ed2be9dee --- /dev/null +++ b/browser/components/loop/content/shared/js/store.js @@ -0,0 +1,96 @@ +/* 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/. */ + +/* global loop:true */ + +var loop = loop || {}; +loop.store = loop.store || {}; + +loop.store.createStore = (function() { + "use strict"; + + var baseStorePrototype = { + __registerActions: function(actions) { + // check that store methods are implemented + actions.forEach(function(handler) { + if (typeof this[handler] !== "function") { + throw new Error("Store should implement an action handler for " + + handler); + } + }, this); + this.dispatcher.register(this, actions); + }, + + /** + * Proxy helper for dispatching an action from this store. + * + * @param {sharedAction.Action} action The action to dispatch. + */ + dispatchAction: function(action) { + this.dispatcher.dispatch(action); + }, + + /** + * Returns current store state. You can request a given state property by + * providing the `key` argument. + * + * @param {String|undefined} key An optional state property name. + * @return {Mixed} + */ + getStoreState: function(key) { + return key ? this._storeState[key] : this._storeState; + }, + + /** + * Updates store state and trigger a global "change" event, plus one for + * each provided newState property. + * + * @param {Object} newState The new store state object. + */ + setStoreState: function(newState) { + for (var key in newState) { + this._storeState[key] = newState[key]; + this.trigger("change:" + key); + } + this.trigger("change"); + } + }; + + /** + * Creates a new Store constructor. + * + * @param {Object} storeProto The store prototype. + * @return {Function} A store constructor. + */ + function createStore(storeProto) { + var BaseStore = function(dispatcher, options) { + options = options || {}; + + if (!dispatcher) { + throw new Error("Missing required dispatcher"); + } + this.dispatcher = dispatcher; + if (Array.isArray(this.actions)) { + this.__registerActions(this.actions); + } + + if (typeof this.initialize === "function") { + this.initialize(options); + } + + if (typeof this.getInitialStoreState === "function") { + this._storeState = this.getInitialStoreState(); + } else { + this._storeState = {}; + } + }; + BaseStore.prototype = _.extend({}, // destination object + Backbone.Events, + baseStorePrototype, + storeProto); + return BaseStore; + } + + return createStore; +})(); diff --git a/browser/components/loop/jar.mn b/browser/components/loop/jar.mn index d69d0b97baf0..d8c200733040 100644 --- a/browser/components/loop/jar.mn +++ b/browser/components/loop/jar.mn @@ -67,6 +67,7 @@ browser.jar: # Shared scripts content/browser/loop/shared/js/actions.js (content/shared/js/actions.js) content/browser/loop/shared/js/conversationStore.js (content/shared/js/conversationStore.js) + content/browser/loop/shared/js/store.js (content/shared/js/store.js) content/browser/loop/shared/js/roomStore.js (content/shared/js/roomStore.js) content/browser/loop/shared/js/activeRoomStore.js (content/shared/js/activeRoomStore.js) content/browser/loop/shared/js/dispatcher.js (content/shared/js/dispatcher.js) diff --git a/browser/components/loop/standalone/content/index.html b/browser/components/loop/standalone/content/index.html index 77a15d65e40b..f162ed07a3c0 100644 --- a/browser/components/loop/standalone/content/index.html +++ b/browser/components/loop/standalone/content/index.html @@ -42,7 +42,7 @@ myCustomEvent.prototype = window.Event.prototype; window.CustomEvent = myCustomEvent; } - + // To support IE for the l10n-gaia library on IE <= 10. if (!"language" in navigator) { navigator.language = navigator.browserLanguage; @@ -97,6 +97,7 @@ + diff --git a/browser/components/loop/standalone/content/js/webapp.js b/browser/components/loop/standalone/content/js/webapp.js index 6a28ef5d9ee4..ada6950aeaae 100644 --- a/browser/components/loop/standalone/content/js/webapp.js +++ b/browser/components/loop/standalone/content/js/webapp.js @@ -999,8 +999,7 @@ loop.webapp = (function($, _, OT, mozL10n) { helper: helper, sdk: OT }); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: standaloneMozLoop, sdkDriver: sdkDriver }); diff --git a/browser/components/loop/standalone/content/js/webapp.jsx b/browser/components/loop/standalone/content/js/webapp.jsx index 8f6dd0c3d8fd..aa4908db64b4 100644 --- a/browser/components/loop/standalone/content/js/webapp.jsx +++ b/browser/components/loop/standalone/content/js/webapp.jsx @@ -999,8 +999,7 @@ loop.webapp = (function($, _, OT, mozL10n) { helper: helper, sdk: OT }); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: standaloneMozLoop, sdkDriver: sdkDriver }); diff --git a/browser/components/loop/test/desktop-local/conversation_test.js b/browser/components/loop/test/desktop-local/conversation_test.js index faab6ecae0c0..d66908cf03fe 100644 --- a/browser/components/loop/test/desktop-local/conversation_test.js +++ b/browser/components/loop/test/desktop-local/conversation_test.js @@ -169,9 +169,8 @@ describe("loop.conversation", function() { dispatcher: dispatcher, sdkDriver: {} }); - roomStore = new loop.store.RoomStore({ + roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop, - dispatcher: dispatcher }); conversationAppStore = new loop.store.ConversationAppStore({ dispatcher: dispatcher, diff --git a/browser/components/loop/test/desktop-local/index.html b/browser/components/loop/test/desktop-local/index.html index 1bc40a44185b..ec206b20fa33 100644 --- a/browser/components/loop/test/desktop-local/index.html +++ b/browser/components/loop/test/desktop-local/index.html @@ -43,6 +43,7 @@ + diff --git a/browser/components/loop/test/desktop-local/panel_test.js b/browser/components/loop/test/desktop-local/panel_test.js index 894c7a6d48ff..bb1368cf9d6c 100644 --- a/browser/components/loop/test/desktop-local/panel_test.js +++ b/browser/components/loop/test/desktop-local/panel_test.js @@ -156,8 +156,7 @@ describe("loop.panel", function() { }; dispatcher = new loop.Dispatcher(); - roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop }); }); @@ -788,8 +787,7 @@ describe("loop.panel", function() { beforeEach(function() { fakeEmail = "fakeEmail@example.com"; dispatcher = new loop.Dispatcher(); - roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop }); roomStore.setStoreState({ diff --git a/browser/components/loop/test/desktop-local/roomViews_test.js b/browser/components/loop/test/desktop-local/roomViews_test.js index 25c5f2950112..5885caca2c9d 100644 --- a/browser/components/loop/test/desktop-local/roomViews_test.js +++ b/browser/components/loop/test/desktop-local/roomViews_test.js @@ -30,13 +30,11 @@ describe("loop.roomViews", function () { return x; }); - activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: {}, sdkDriver: {} }); - roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: {}, activeRoomStore: activeRoomStore }); diff --git a/browser/components/loop/test/shared/activeRoomStore_test.js b/browser/components/loop/test/shared/activeRoomStore_test.js index 5e681858a450..2704dcbb8030 100644 --- a/browser/components/loop/test/shared/activeRoomStore_test.js +++ b/browser/components/loop/test/shared/activeRoomStore_test.js @@ -44,8 +44,7 @@ describe("loop.store.ActiveRoomStore", function () { multiplexGum: fakeMultiplexGum }; - store = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + store = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: fakeMozLoop, sdkDriver: fakeSdkDriver }); @@ -56,21 +55,15 @@ describe("loop.store.ActiveRoomStore", function () { }); describe("#constructor", function() { - it("should throw an error if the dispatcher is missing", function() { - expect(function() { - new loop.store.ActiveRoomStore({mozLoop: {}}); - }).to.Throw(/dispatcher/); - }); - it("should throw an error if mozLoop is missing", function() { expect(function() { - new loop.store.ActiveRoomStore({dispatcher: dispatcher}); + new loop.store.ActiveRoomStore(dispatcher); }).to.Throw(/mozLoop/); }); it("should throw an error if sdkDriver is missing", function() { expect(function() { - new loop.store.ActiveRoomStore({dispatcher: dispatcher, mozLoop: {}}); + new loop.store.ActiveRoomStore(dispatcher, {mozLoop: {}}); }).to.Throw(/sdkDriver/); }); }); @@ -143,6 +136,10 @@ describe("loop.store.ActiveRoomStore", function () { roomUrl: "http://invalid" }; + store = new loop.store.ActiveRoomStore(dispatcher, { + mozLoop: fakeMozLoop, + sdkDriver: {} + }); fakeMozLoop.rooms.get. withArgs(fakeToken). callsArgOnWith(1, // index of callback argument diff --git a/browser/components/loop/test/shared/index.html b/browser/components/loop/test/shared/index.html index 402e2cb46d84..8d697a75cb4b 100644 --- a/browser/components/loop/test/shared/index.html +++ b/browser/components/loop/test/shared/index.html @@ -43,9 +43,10 @@ + - + @@ -59,6 +60,7 @@ + + diff --git a/browser/components/loop/test/standalone/standaloneRoomViews_test.js b/browser/components/loop/test/standalone/standaloneRoomViews_test.js index d63c6ecdc07e..fb3892780f2c 100644 --- a/browser/components/loop/test/standalone/standaloneRoomViews_test.js +++ b/browser/components/loop/test/standalone/standaloneRoomViews_test.js @@ -18,8 +18,7 @@ describe("loop.standaloneRoomViews", function() { sandbox = sinon.sandbox.create(); dispatcher = new loop.Dispatcher(); dispatch = sandbox.stub(dispatcher, "dispatch"); - activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: {}, sdkDriver: {} }); diff --git a/browser/components/loop/test/standalone/webapp_test.js b/browser/components/loop/test/standalone/webapp_test.js index 8962f4fbaee5..21ce7f1690a8 100644 --- a/browser/components/loop/test/standalone/webapp_test.js +++ b/browser/components/loop/test/standalone/webapp_test.js @@ -610,8 +610,7 @@ describe("loop.webapp", function() { baseServerUrl: "fakeUrl" }); dispatcher = new loop.Dispatcher(); - activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: {}, sdkDriver: {} }); diff --git a/browser/components/loop/ui/index.html b/browser/components/loop/ui/index.html index 0c7a348fb3e2..85f8740774d6 100644 --- a/browser/components/loop/ui/index.html +++ b/browser/components/loop/ui/index.html @@ -41,8 +41,9 @@ - + + diff --git a/browser/components/loop/ui/ui-showcase.js b/browser/components/loop/ui/ui-showcase.js index 5e6310135aa5..cc74e6afb602 100644 --- a/browser/components/loop/ui/ui-showcase.js +++ b/browser/components/loop/ui/ui-showcase.js @@ -62,13 +62,11 @@ ); var dispatcher = new loop.Dispatcher(); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: navigator.mozLoop, sdkDriver: {} }); - var roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + var roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop }); diff --git a/browser/components/loop/ui/ui-showcase.jsx b/browser/components/loop/ui/ui-showcase.jsx index 20dd786f78b8..43668b500183 100644 --- a/browser/components/loop/ui/ui-showcase.jsx +++ b/browser/components/loop/ui/ui-showcase.jsx @@ -62,13 +62,11 @@ ); var dispatcher = new loop.Dispatcher(); - var activeRoomStore = new loop.store.ActiveRoomStore({ - dispatcher: dispatcher, + var activeRoomStore = new loop.store.ActiveRoomStore(dispatcher, { mozLoop: navigator.mozLoop, sdkDriver: {} }); - var roomStore = new loop.store.RoomStore({ - dispatcher: dispatcher, + var roomStore = new loop.store.RoomStore(dispatcher, { mozLoop: navigator.mozLoop });