«ожидается» в открывающих и закрывающих скобках, ESLint и JavaScript - PullRequest
0 голосов
/ 01 июля 2018

Я работаю над этой проблемой около трех часов, и я не могу найти, что я сделал неправильно или как это исправить. Я искал стек и ничего не нашел, и я не уверен, является ли это синтаксисом или я сделал что-то ужасно неправильное в моих программах, не связанных с синтаксисом (логические ошибки и т. Д.). Я новичок как в JS, так и в stackoverflow, поэтому прошу прощения, если мое форматирование, способ задать этот вопрос или вопрос в целом неверны.

import Vue from 'vue'
import Vuex from 'vuex'
import sourceData from '@/data'
import {countObjectProperties} from '@/utils'

Vue.use(Vuex)

const makeAppendChildToParentMutation = ({parent, child}) =>
    (state, {childId, parentId}) => {
      const resource = state[parent][parentId]
        if (!resource[child]) {
          Vue.set(resource, child, {})
        }
      Vue.set(resource[child], childId, childId)
    }
export default new Vuex.Store({

  state: {
    ...sourceData,
    authId: 'VXjpr2WHa8Ux4Bnggym8QFLdv5C3'
  },

  getters: {
    authUser (state) {
      return state.users[state.authId]
    },

      userThreadsCount: state => id => countObjectProperties(state.users[id].threads),
      userPostsCount: state => id => countObjectProperties(state.users[id].posts)
    },
  actions: {
    createPost ({commit, state}, post) {
      const postId = 'greatPost' + Math.random()
      post['.key'] = postId
      post.userId = state.authId
      post.publishedAt = Math.floor(Date.now() / 1000)
      commit('setPost', {
                  postId: id,
                  post: {
                    ...post,
                      text,
                      edited: {
                        at: Math.floor(Date.now() / 1000),
                          by: state.authId
                      }
                  }
              })
      commit('appendPostToThread', {threadId: post.threadId, postId})
      commit('appendPostToUser', {userId: post.userId, postId})
      return Promise.resolve(state.posts[postId])
    },
    createThread ({state, commit, dispatch}, {text, title, forumId}) {
      return new Promise((resolve, reject) => {
        const threadId = 'greatThread' + Math.random()
          const userId = state.authId
          const publishedAt = Math.floor(Date.now() / 1000)
      const thread = {'.key': threadId, title, forumId, publishedAt, userId}
      commit('setThread', {threadId, thread})
      commit('appendThreadToForum', {forumId, threadId})
      commit('appendThreadToUser', {userId, threadId})
      dispatch('createPost', {text, threadId})
        .then(post => {
          commit('setThread', {threadId, thread: {...thread, firstPostId: post['.key']}})
        })
      resolve(state.threads[threadId])
    },
        updateThread ({state, commit, dispatch}, {title, text, id}) {
              return new Promise((resolve, reject) => {
                    const thread = state.threads[id]
                    const newThread = {...thread, title}
                    commit('setThread', {thread: newThread, threadId: id})

Здесь также есть ошибка ^ (обновить строку потока), ожидающая запятую сразу после закрывающих скобок и перед открывающей скобкой

                dispatch('updatePost', {id: thread.firstPostId, text})
                          .then(() => {
                              resolve(newThread)
                            })
                  })
        }
      updatePost ({state, commit}, {id, text}); {
              return new Promise((resolve, reject) => {
                    const post = state.posts[id]
                    commit('setPost', {postId: id, post: {...post, text}})
                    resolve(post)
                  })
              }
      updateUser ({commit}, user);{
      commit('setUser', {userId: user['.key'], user})
    }},
  setThread (state, {thread, threadId}) {
    Vue.set(state.threads, threadId, thread)
  },

  mutations: {
    setPost (state, {post, postId}) {
      Vue.set(state.posts, postId, post)
    },
    setUser (state, {user, userId}) {
      Vue.set(state.users, userId, user)
    },
    AppendPostToThread (state, {postId, threadId}) {
      const thread = state.threads[threadId]
      if (!thread.posts) {
        Vue.set(thread, 'posts', {})
      }
      Vue.set(thread.posts, postId, postId)
    },
    appendPostToUser (state, {postId, userId}) {
      const user = state.users[userId]
      if (!user.posts) {
        Vue.set(user, 'posts', {})
      }
      Vue.set(user.posts, postId, postId)
    },
    appendThreadToForum (state, {forumId, threadId}) {
      const forum = state.forums[forumId]
      if (!forum.threads) {
        Vue.set(forum, 'threads', {})
      }
      Vue.set(forum.threads, threadId, threadId)
    },

    appendThreadToUser (state, {userId, threadId}) {
      const user = state.users[userId]
      if (!user.threads) {
        Vue.set(user, 'threads', {})
      }
      Vue.set(user.threads, threadId, threadId)
    }
    }
})

Проблема связана с последними скобками выше: там написано, что ожидается запятая.

1 Ответ

0 голосов
/ 02 июля 2018

Перед действиями вам не хватает закрывающей скобки для геттеров.

...