From 6f8cf22ba6b36c6ae91a794fad75473c9436b683 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Fri, 26 Dec 2014 16:21:21 -0800 Subject: [PATCH] Converts actions to alt style actions This commit converts most of the actions over to alt style. Since the actions act as a dispatcher we can just dispatch the payload directly. One difference of this can be seen in `ChatServerActionCreators` where we don't separate out the server and view actions using `handleServerAction` and `handleViewAction`. If you do need to know the source of an action or wish to have different behavior for an action you have two options: Dispatch a payload object with a source parameter. ```js receiveAll: function(rawMessages) { this.dispatch({ source: 'server-action', data: rawMessages }) } ``` If you need to have different behavior for server and view actions you can just implement the behavior in the action itself, since the action is a dispatcher. --- .../js/actions/ChatServerActionCreators.js | 37 +++---------------- .../js/actions/ChatThreadActionCreators.js | 30 +++------------ 2 files changed, 12 insertions(+), 55 deletions(-) diff --git a/examples/chat/js/actions/ChatServerActionCreators.js b/examples/chat/js/actions/ChatServerActionCreators.js index 9aa92f40..00a1e4bc 100644 --- a/examples/chat/js/actions/ChatServerActionCreators.js +++ b/examples/chat/js/actions/ChatServerActionCreators.js @@ -1,34 +1,9 @@ -/** - * This file is provided by Facebook for testing and evaluation purposes - * only. Facebook reserves all rights not expressly granted. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +var alt = require('../alt') -var ChatAppDispatcher = require('../dispatcher/ChatAppDispatcher'); -var ChatConstants = require('../constants/ChatConstants'); - -var ActionTypes = ChatConstants.ActionTypes; - -module.exports = { - - receiveAll: function(rawMessages) { - ChatAppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVE_RAW_MESSAGES, - rawMessages: rawMessages - }); - }, - - receiveCreatedMessage: function(createdMessage) { - ChatAppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVE_RAW_CREATED_MESSAGE, - rawMessage: createdMessage - }); +class ChatServerActions { + constructor() { + this.generateActions('receiveCreatedMessage', 'receiveAll') } +} -}; +module.exports = alt.createActions(ChatServerActions) diff --git a/examples/chat/js/actions/ChatThreadActionCreators.js b/examples/chat/js/actions/ChatThreadActionCreators.js index fa63c9cd..e0ffe189 100644 --- a/examples/chat/js/actions/ChatThreadActionCreators.js +++ b/examples/chat/js/actions/ChatThreadActionCreators.js @@ -1,27 +1,9 @@ -/** - * This file is provided by Facebook for testing and evaluation purposes - * only. Facebook reserves all rights not expressly granted. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +var alt = require('../alt') -var ChatAppDispatcher = require('../dispatcher/ChatAppDispatcher'); -var ChatConstants = require('../constants/ChatConstants'); - -var ActionTypes = ChatConstants.ActionTypes; - -module.exports = { - - clickThread: function(threadID) { - ChatAppDispatcher.handleViewAction({ - type: ActionTypes.CLICK_THREAD, - threadID: threadID - }); +class ChatThreadActions { + constructor() { + this.generateActions('clickThread') } +} -}; +module.exports = alt.createActions(ChatThreadActions)