{"size": 1688, "ext": "js", "max_stars_repo_path": "src/components/container/Demo/module/actions.js", "max_stars_repo_name": "barter19/barter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/container/Demo/module/actions.js", "max_issues_repo_name": "barter19/barter", "max_issues_repo_issues_event_min_datetime": "2022-02-10T17:54:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T17:54:28.000Z", "max_forks_repo_path": "src/components/container/Demo/module/actions.js", "max_forks_repo_name": "barter19/barter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 19.1818181818, "max_line_length": 75, "alphanum_fraction": 0.5930094787}
/**
 * Demo Actions
 *
 * These are functions that dispatch (communicate changes to the store) our
 * mutations. Actions do not mutate the state directly, but only commit the
 * mutations.
 *
 * Further Reading: https://vuex.vuejs.org/en/actions.html
 */

import { setI18nLanguage } from '@/i18n';
import {
  UPDATE_NAME,
  INCREMENT,
  DECREMENT,
  GET_REDDIT_POSTS,
  UPDATE_LOCALE,
} from './constants';
import { fetchRedditPosts } from './side-effects';
import { createApolloFetch } from 'apollo-fetch';

const uri = 'http://127.0.0.1:3000/graphql';
const apolloFetch = createApolloFetch({ uri });

const actions = {
  updateName({ commit }, payload) {
    commit({
      type: UPDATE_NAME,
      name: payload.name,
    });
  },
  incrementCounter({ commit }) {
    commit({
      type: INCREMENT,
    });
  },
  decrementCounter({ commit }) {
    commit({
      type: DECREMENT,
    });
  },
  async getRedditPosts({ commit }) {
    commit({
      type: GET_REDDIT_POSTS.REQUEST,
    });

    try {
      const posts = await fetchRedditPosts();

      commit({
        type: GET_REDDIT_POSTS.SUCCESS,
        posts,
      });
    } catch (error) {
      commit({
        type: GET_REDDIT_POSTS.FAILURE,
        error,
      });
    }
  },
  updateLocale({ commit }, payload) {
    const locale = setI18nLanguage(payload.locale);

    commit({
      type: UPDATE_LOCALE,
      locale,
    });
  },
  registerUser(){
    const query = `
    query Users {
      users {
        id
      }
    }`;
  apolloFetch({ query}).then(result => {
    const { data } = result;

  console.log(result);
  })
  .catch(error => {
    //respond to a network error
  });
}
};

export default actions;
