From 1ac0b1b70743333b1549a49070a70e8fa7a1e034 Mon Sep 17 00:00:00 2001 From: Kennet Postigo Date: Fri, 29 Jan 2016 15:00:48 -0500 Subject: [PATCH] change to exporting modules with es6 export default --- src/index.js | 4 +-- src/reachGraphQL.js | 6 ++--- src/reachWithDispatch.js | 4 +-- src/reachWithOpts.js | 54 ++++++++++++++++++++-------------------- src/utils/transport.js | 12 ++++----- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/index.js b/src/index.js index 654d91a..5a0ec3d 100644 --- a/src/index.js +++ b/src/index.js @@ -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 { diff --git a/src/reachGraphQL.js b/src/reachGraphQL.js index 9594546..48a721b 100644 --- a/src/reachGraphQL.js +++ b/src/reachGraphQL.js @@ -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); diff --git a/src/reachWithDispatch.js b/src/reachWithDispatch.js index c87ce0f..c0dfdc4 100644 --- a/src/reachWithDispatch.js +++ b/src/reachWithDispatch.js @@ -1,4 +1,4 @@ -import {transport} from './utils/transport.js'; +import { transport } from './utils/transport.js'; require('babel-polyfill'); /** @@ -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); diff --git a/src/reachWithOpts.js b/src/reachWithOpts.js index 8f9c4fa..0b94ace 100644 --- a/src/reachWithOpts.js +++ b/src/reachWithOpts.js @@ -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 diff --git a/src/utils/transport.js b/src/utils/transport.js index 525faa2..fa085b1 100644 --- a/src/utils/transport.js +++ b/src/utils/transport.js @@ -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: { @@ -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; }); - }