Permalink
Browse files

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.
  • Loading branch information...
goatslacker committed Dec 27, 2014
1 parent 75ffdb5 commit 6f8cf22ba6b36c6ae91a794fad75473c9436b683
@@ -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)
@@ -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)

1 comment on commit 6f8cf22

@andyshora

This comment has been minimized.

Show comment
Hide comment
@andyshora

andyshora Jun 23, 2015

Wow. Amazing amount of code removed! claps hands

andyshora commented on 6f8cf22 Jun 23, 2015

Wow. Amazing amount of code removed! claps hands

Please sign in to comment.