浏览代码

clean up mutations

Evan You 9 年之前
父节点
当前提交
8681ef687c
共有 1 个文件被更改,包括 4 次插入9 次删除
  1. 4 9
      examples/chat/vuex/mutations.js

+ 4 - 9
examples/chat/vuex/mutations.js

@@ -2,15 +2,12 @@ import { set } from 'vue'
 import * as types from './mutation-types'
 
 export default {
-
   [types.RECEIVE_ALL] (state, messages) {
     let latestMessage
     messages.forEach(message => {
       // create new thread if the thread doesn't exist
-      const threadID = message.threadID
-      let thread = state.threads[threadID]
-      if (!thread) {
-        thread = createThread(state, threadID, message.threadName)
+      if (!state.threads[message.threadID]) {
+        createThread(state, message.threadID, message.threadName)
       }
       // mark the latest message
       if (!latestMessage || message.timestamp > latestMessage.timestamp) {
@@ -33,14 +30,12 @@ export default {
 }
 
 function createThread (state, id, name) {
-  const thread = {
+  set(state.threads, id, {
     id,
     name,
     messages: [],
     lastMessage: null
-  }
-  set(state.threads, id, thread)
-  return thread
+  })
 }
 
 function addMessage (state, message) {