Skip to content

Commit

Permalink
change to exporting modules with es6 export default
Browse files Browse the repository at this point in the history
  • Loading branch information
kennetpostigo committed Jan 29, 2016
1 parent f485adf commit 1ac0b1b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {reachGraphQL} from './reachGraphQL.js';
import {reachWithDispatch} from './reachWithDispatch.js';
import { reachGraphQL } from './reachGraphQL.js';
import { reachWithDispatch } from './reachWithDispatch.js';
require('babel-polyfill');

export {
Expand Down
6 changes: 3 additions & 3 deletions src/reachGraphQL.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {transport} from './utils/transport.js';
import { transport } from './utils/transport.js';
require('babel-polyfill');

/**
* [reachGraphQL Makes queres or mutations against GraphQL]
* @param {[String]} path [path to the GraphQL server]
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
* @param {[object]} queryParams = {} [should contain object with different query params]
* @param {[object]} queryParams = {} [Should contain object with different query params]
* @return {[Object]} [Data that was queried or mutated]
*/
export function reachGraphQL (path, query, queryParams = {}) {
export default function reachGraphQL (path, query, queryParams = {}) {
return async () => {
try{
let response = await transport(path, query, queryParams);
Expand Down
4 changes: 2 additions & 2 deletions src/reachWithDispatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {transport} from './utils/transport.js';
import { transport } from './utils/transport.js';
require('babel-polyfill');

/**
Expand All @@ -9,7 +9,7 @@ require('babel-polyfill');
* @param {[type]} actionCreator = ( [The actionCreator to dispatch]
* @return {[function]} [dispatch to store]
*/
export function reachWithDispatch (path, query, queryParams = {}, actionCreator) {
export default function reachWithDispatch (path, query, queryParams = {}, actionCreator) {
return async (dispatch) => {
try{
let response = await transport(path, query, queryParams);
Expand Down
54 changes: 27 additions & 27 deletions src/reachWithOpts.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import {transport} from './utils/transport.js';
require('babel-polyfill');


// Use currying to reduce size of the parameters?
// If so how do people not familiar with currying work around this
// store or dispatch?



export function reachWithOpts (path, query, queryParams = {}, store, actionCreator, retry) {
//1. store.getState(propertyToChange)
//2. store.dispatch(actionCreator())
//3. return async dispatch => {
// try{
//4. let response = await transport(path, query, queryParams, retry);
//5. } catch(error) {
// try{
// let response = await transport(path, query, queryParams)
//6. } catch(error) {
// dispatch(actionCreator(1));
//7. console.log(error);
// }
// }
// }
}

// import {transport} from './utils/transport.js';
// require('babel-polyfill');
//
//
// // Use currying to reduce size of the parameters?
// // If so how do people not familiar with currying work around this
// // store or dispatch?
//
//
//
// export function reachWithOpts (path, query, queryParams = {}, store, actionCreator, retry) {
// 1. store.getState(propertyToChange)
// 2. store.dispatch(actionCreator())
// 3. return async dispatch => {
// try{
// 4. let response = await transport(path, query, queryParams, retry);
// 5. } catch(error) {
// try{
// let response = await transport(path, query, queryParams)
// 6. } catch(error) {
// dispatch(actionCreator(1));
// 7. console.log(error);
// }
// }
// }
// }
//

//1. getState of the current property value you are going to act upon
//2. dispatch synchronous function to update client
Expand Down
12 changes: 5 additions & 7 deletions src/utils/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ require('babel-polyfill');
* @param {[Object]} queryParams = {} [Params to pass into query]
* @return {[Promise]} [Promise containing payload]
*/
export function transport (path, query, queryParams = {}) {

export default function transport (path, query, queryParams = {}) {
return fetch(path, {
method: 'POST',
headers: {
Expand All @@ -23,11 +22,10 @@ export function transport (path, query, queryParams = {}) {
.then((response) => {
return response.json();
})
.then((response) => {
if (response && response.errors) {
throw new Error(response.errors);
.then((responseBody) => {
if (responseBody && responseBody.errors) {
throw new Error(responseBody.errors);
}
return response.data;
return responseBody.data;
});

}

0 comments on commit 1ac0b1b

Please sign in to comment.