-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
75ffdb5
commit 6f8cf22
Showing
2 changed files
with
12 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
6f8cf22
There was a problem hiding this comment.
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