Skip to content

Commit

Permalink
Converts actions to alt style actions
Browse files Browse the repository at this point in the history
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 6f8cf22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
37 changes: 6 additions & 31 deletions examples/chat/js/actions/ChatServerActionCreators.js
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 6 additions & 24 deletions examples/chat/js/actions/ChatThreadActionCreators.js
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Amazing amount of code removed! claps hands

Please sign in to comment.