Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging function #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .babelrc
100644 → 100755
Empty file.
Empty file modified .coveralls.yml
100644 → 100755
Empty file.
Empty file modified .eslintrc
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .npmignore
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified docs/.gitignore
100644 → 100755
Empty file.
Empty file modified docs/_config.yml
100644 → 100755
Empty file.
Empty file modified docs/package.json
100644 → 100755
Empty file.
Empty file modified docs/scaffolds/draft.md
100644 → 100755
Empty file.
Empty file modified docs/scaffolds/page.md
100644 → 100755
Empty file.
Empty file modified docs/scaffolds/post.md
100644 → 100755
Empty file.
Empty file modified docs/source/_data/nav.yml
100644 → 100755
Empty file.
Empty file modified docs/source/data-connect.md
100644 → 100755
Empty file.
Empty file modified docs/source/fragments.md
100644 → 100755
Empty file.
Empty file modified docs/source/how-it-works.md
100644 → 100755
Empty file.
Empty file modified docs/source/images/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/source/images/logo_image.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/source/images/relate_scheme.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/source/index.md
100644 → 100755
Empty file.
Empty file modified docs/source/installation.md
100644 → 100755
Empty file.
Empty file modified docs/source/intersect.md
100644 → 100755
Empty file.
Empty file modified docs/source/mutations.md
100644 → 100755
Empty file.
Empty file modified docs/source/reducer.md
100644 → 100755
Empty file.
Empty file modified docs/source/root-data-connect.md
100644 → 100755
Empty file.
Empty file modified docs/source/server-side.md
100644 → 100755
Empty file.
Empty file modified docs/source/settings.md
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/_config.yml
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/layout/default.swig
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/_code.scss
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/_content.scss
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/_menu.scss
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/_typography.scss
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/bootstrap.min.css
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/docs.scss
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/css/font-awesome.min.css
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/fonts/FontAwesome.otf
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/fonts/fontawesome-webfont.eot
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/fonts/fontawesome-webfont.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/themes/relate/source/fonts/fontawesome-webfont.ttf
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/fonts/fontawesome-webfont.woff
100644 → 100755
Empty file.
Empty file modified docs/themes/relate/source/fonts/fontawesome-webfont.woff2
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions lib/actions/mutation.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ export default function (options, callback = false) {
mutates: options.mutates,
headers: options.headers || headers,
body: options.body || body,
endpoint: options.endpoint || endpoint
endpoint: options.endpoint || endpoint,
logging: options.logging
}).then((result) => {
if (callback !== false) {
callback(result, dispatch);
// result = { data: {...}, errors: {...} }
callback({...result, dispatch});
}
});
};
Expand Down
3 changes: 2 additions & 1 deletion lib/actions/query.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default function graphql (
fragments,
headers: config && config.headers || headers,
body: config && config.body || body,
endpoint: config && config.endpoint || endpoint
endpoint: config && config.endpoint || endpoint,
logging: config && config.logging
});
}

Expand Down
Empty file modified lib/actions/remove-connector.js
100644 → 100755
Empty file.
Empty file modified lib/actions/settings.js
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion lib/actions/types.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default {
removeHeader: 'RELATE_REMOVE_HEADER',
setEndpoint: 'RELATE_SET_ENDPOINT',
setBody: 'RELATE_SET_BODY',
removeBody: 'RELATE_REMOVE_BODY'
removeBody: 'RELATE_REMOVE_BODY',
setLoggingFn: 'RELATE_SET_LOGGING_FUNCTION'
};
Empty file modified lib/decorators/data-connect.js
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/decorators/root-data-connect.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function rootDataConnect (config) {
config,
relate_ssr
)
).then((data) => {
).then(({data}) => {
this.deferred.resolve(data);
}).catch((err) => {
warning(false, err);
Expand Down
Empty file modified lib/helpers/connectors-ids.js
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions lib/helpers/errorParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function errorParser (error) {
if (error && error.status === 400) {
return (error.response && error.response.body && error.response.body.errors)
|| error.message
|| [{message: 'Unknown error'}];
}
return error && [error] || [{message: 'Unknown error'}];
}
Empty file modified lib/helpers/get-variables.js
100644 → 100755
Empty file.
Empty file modified lib/helpers/iterate-field.js
100644 → 100755
Empty file.
Empty file modified lib/helpers/iterate-node.js
100644 → 100755
Empty file.
19 changes: 17 additions & 2 deletions lib/helpers/request.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import request from 'superagent';
import errorParser from '../helpers/errorParser';
import Q from 'q';

export default function doRequest ({dispatch, query, variables, type, endpoint, headers, body, ...params}) {
export default function doRequest (
{
dispatch,
query,
variables,
type,
endpoint,
headers,
body,
logging,
...params
}
) {
return new Q()
.then(() => {
const deferred = Q.defer();
Expand All @@ -20,6 +33,7 @@ export default function doRequest ({dispatch, query, variables, type, endpoint,
req
.end((error, res) => {
if (error) {
logging && logging({errors: errorParser(error)}, dispatch);
deferred.reject(error);
} else {
deferred.resolve(res.body);
Expand All @@ -28,8 +42,9 @@ export default function doRequest ({dispatch, query, variables, type, endpoint,

if (dispatch) {
promise = promise.then(({data, errors}) => {
logging && logging({data, errors}, dispatch);
dispatch({type, data, errors, ...params});
return data;
return {data, errors};
});
}

Expand Down
Empty file modified lib/index.js
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions lib/reducer/reducer.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export function relateReducer (_state = defaultState, action = {}) {
});
}

if (action.type === actionTypes.setLoggingFn) {
return Object.assign({}, state, {
logging: action.logging
});
}

return state;
}

Expand Down
Empty file modified lib/server/get-data-dependencies.js
100644 → 100755
Empty file.
Empty file modified lib/store/connectors.js
100644 → 100755
Empty file.
Empty file modified lib/store/db.js
100644 → 100755
Empty file.
Empty file modified lib/store/index.js
100644 → 100755
Empty file.
Empty file modified lib/store/normalize.js
100644 → 100755
Empty file.
Empty file modified package.json
100644 → 100755
Empty file.
Empty file modified test/.eslintrc
100644 → 100755
Empty file.
Empty file modified test/decorators/root-data-connect.js
100644 → 100755
Empty file.
Empty file modified test/helpers/get-variables.js
100644 → 100755
Empty file.
Empty file modified test/index.js
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions test/reducer/reducer.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import expect from 'expect';

import {relateReducer, relateReducerInit, actionTypes} from '../../lib';


describe('Reducer', () => {
it('Does not alter state if not a Relate action', () => {
const state = {something: 1};
Expand Down
Empty file modified test/reducer/settings.js
100644 → 100755
Empty file.
Empty file modified test/store/connectors.js
100644 → 100755
Empty file.
Empty file modified test/store/db.js
100644 → 100755
Empty file.
Empty file modified test/store/normalize.js
100644 → 100755
Empty file.
Empty file modified webpack.config.js
100644 → 100755
Empty file.