vuex#ActionContext TypeScript Examples

The following examples show how to use vuex#ActionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
actions = {
  addItemToCart(
    { commit }: ActionContext<CartState, unknown>,
    product: Product
  ) {
    commit(mutationTypes.ADD_ITEM_TO_CART, product)
  },
  setTextFilter(
    { commit }: ActionContext<CartState, unknown>,
    newFilter: string
  ) {
    commit(mutationTypes.SET_TEXT_FILTER, newFilter)
  },
}
Example #2
Source File: index.ts    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
actions: ActionTree<ICartState, unknown> & CartActionsType = {
  [CartActionEnums.ADD_ITEM_TO_CART](
    { commit }: ActionContext<ICartState, unknown>,
    product: Product
  ) {
    if (!product) return
    commit(CartMutationEnums.ADD_ITEM_TO_CART, product)
  },
  [CartActionEnums.REMOVE_ITEM_FROM_CART](
    { commit }: ActionContext<ICartState, unknown>,
    id: Product['id']
  ) {
    if (!id) return
    commit(CartMutationEnums.REMOVE_ITEM_FROM_CART, id)
  },
  [CartActionEnums.DECREMENT_QUANTITY](
    { commit }: ActionContext<ICartState, unknown>,
    id: Product['id']
  ) {
    if (!id) return
    commit(CartMutationEnums.DECREMENT_QUANTITY, id)
  },
}
Example #3
Source File: index.ts    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
actions: ActionTree<CartState, unknown> & CartActions = {
  [CartActionEnums.ADD_ITEM_TO_CART]: (
    { commit }: ActionContext<CartState, unknown>,
    payload: Product
  ) => {
    if (!payload) return
    commit(CartMutationsEnums.ADD_ITEM_TO_CART, payload)
  },
}
Example #4
Source File: message.ts    From speedy-im with MIT License 6 votes vote down vote up
actions = {
  async getUnreadMessage({ commit }: ActionContext<State, any>) {
    const [err, res] = await request({
      url: '/user/unreadMessage',
      method: 'get',
    });
    if (res && res.errno === 200) {
      commit('SET_USER_MESSAGES', { messages: res.data });
    }
  },
  setMessage({ commit }: ActionContext<State, any>, payload: { messages: MessageRecord[] }) {
    const { messages } = payload;
    commit('SET_USER_MESSAGES', { messages });
  },
  recoverMessages({ commit }: ActionContext<State, any>, payload: { messages: Record<number, MessageRecord[]> }) {
    const { messages } = payload;
    commit('RECOVER_MESSAGE', { messages });
  },
  updateMessage({ commit }: ActionContext<State, any>, payload: { messages: { id: number, hash: string, friend_id: number } }) {
    const { messages } = payload;
    commit('UPDATE_MESSAGE_ID', { messages });
  }
}
Example #5
Source File: authStore.ts    From Vue3-Vite-Vuetify3-Typescript-Template with MIT License 6 votes vote down vote up
AuthStore = {
  state: {
    loggedIn: false,
  },
  getters: {
    getAuth(state: Auth): boolean {
      return state.loggedIn
    },
  },
  actions: {
    changeAuth(context: ActionContext<Auth, Auth>, data: boolean): void {
      context.commit('changeAuth', data)
    },
  },
  mutations: {
    changeAuth(state: Auth, data: boolean): void {
      state.loggedIn = data
    },
  },
}
Example #6
Source File: registerProductsMapping.ts    From vue-storefront-1 with MIT License 6 votes vote down vote up
export default async function registerProductsMapping ({ dispatch }: ActionContext<any, RootState>, products = []): Promise<void> {
  await Promise.all(products.map(product => {
    if (product.url_path) {
      const { url_path, sku, slug, type_id, parentSku } = product
      return dispatch('url/registerMapping', {
        url: localizedDispatcherRoute(url_path),
        routeData: transformProductUrl({ sku, parentSku, slug, type_id })
      }, { root: true })
    }
  }))
}
Example #7
Source File: index.ts    From master-frontend-lemoncode with MIT License 5 votes vote down vote up
actions = {
  addItemToCart(
    { commit }: ActionContext<CartState, unknown>,
    product: Product
  ) {
    commit(mutationTypes.ADD_ITEM_TO_CART, product)
  },
}
Example #8
Source File: user.ts    From speedy-im with MIT License 5 votes vote down vote up
actions = {
  async getFriendsList({ commit }: ActionContext<State, any>) {
    const [err, res] = await request({
      url: '/user/friends',
      method: 'get',
    });
    if (res && res.errno === 200) {
      commit('SET_USER_FRIENDS', { friends: res.data });
    }
  },
  async login({ commit, dispatch }: ActionContext<State, any>, { mobile, password }: { mobile: number, password: string }) {
    const [err, res] = await request({
      url: '/user/signIn',
      method: 'PUT',
      data: {
        mobile,
        password,
      }
    });
    if (res && res.errno === 200) {
      await dispatch('getFriendsList');
      commit('SET_USER_INFO', { user_info: res.data });
      uni.setStorageSync('token', res.data.token);
      // 登陆成功后,建立ws连接
      Chat.setup();
      return {
        errno: 200,
        errmsg: '',
        data: res.data,
      };
    }
    return {
      errno: res && res.errno || 1,
      errmsg: res && res.errmsg || '网络错误',
      data: null,
    };
  },
  async autoLogin({ commit, dispatch }: ActionContext<State, any>) {
    const [err, res] = await request({
      url: '/user/info',
    });
    if (res && res.errno === 200) {
      await dispatch('getFriendsList');
      commit('SET_USER_INFO', { user_info: res.data });
      // 登陆成功后,建立ws连接
      Chat.setup();
      return {
        errno: 200,
        errmsg: '',
        data: res.data,
      };
    }
    return {
      errno: res && res.errno || 1,
      errmsg: res && res.errmsg || '网络错误',
      data: null,
    };
  },
  setRecentContacts({ commit }: ActionContext<State, any>, { friend_id }: { friend_id: number }) {
    commit('SET_RECENT_CONTACT', { friend_id });
  },
  setFullRecentContacts({ commit }: ActionContext<State, any>, { list }: { list: number[] }) {
    commit('SET_FULL_RECENT_CONTACT', { list });
  },
}