Skip to content

Commit

Permalink
Converts last action
Browse files Browse the repository at this point in the history
Converting the last action left over and adding a new util that uses the
function found in MessageStore for generating the message data.
  • Loading branch information
goatslacker committed Dec 27, 2014
1 parent 6f8cf22 commit 58ea141
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
36 changes: 10 additions & 26 deletions examples/chat/js/actions/ChatMessageActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
/**
* 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 ChatWebAPIUtils = require('../utils/ChatWebAPIUtils');
var MessageStore = require('../stores/MessageStore');
var ChatWebAPIUtils = require('../utils/ChatWebAPIUtils')
var ChatMessageDataUtils = require('../utils/ChatMessageDataUtils')

var ActionTypes = ChatConstants.ActionTypes;
class ChatMessageActions {
createMessage(text) {
this.dispatch(text)

module.exports = {

createMessage: function(text) {
ChatAppDispatcher.handleViewAction({
type: ActionTypes.CREATE_MESSAGE,
text: text
});
var message = MessageStore.getCreatedMessageData(text);
ChatWebAPIUtils.createMessage(message);
var message = ChatMessageDataUtils.getCreatedMessageData(text)
ChatWebAPIUtils.createMessage(message)
}
}

};
module.exports = alt.createActions(ChatMessageActions)
17 changes: 17 additions & 0 deletions examples/chat/js/utils/ChatMessageDataUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var ThreadStore = require('../stores/ThreadStore')

class Chatmessage2Utils {
static getCreatedMessageData(text) {
var timestamp = Date.now()
return {
id: 'm_' + timestamp,
threadID: ThreadStore.getCurrentID(),
authorName: 'Bill', // hard coded for the example
date: new Date(timestamp),
text: text,
isRead: true
}
}
}

module.exports = Chatmessage2Utils

0 comments on commit 58ea141

Please sign in to comment.