From 645aaa09ae6c7bc050eceaa62fd76f0858abdd3c Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 24 Aug 2017 18:40:38 +0700 Subject: [PATCH] Add some docs --- client/coral-admin/src/services/notification.js | 5 +++++ client/coral-framework/services/bootstrap.js | 12 +++++++++++- client/coral-framework/services/client.js | 11 +++++++++-- client/coral-framework/services/events.js | 6 ++++++ client/coral-framework/services/graphqlRegistry.js | 5 +++++ client/coral-framework/services/history.js | 5 +++++ client/coral-framework/services/notification.js | 5 +++++ client/coral-framework/services/plugins.js | 9 +++++++-- client/coral-framework/services/rest.js | 7 +++++++ client/coral-framework/services/storage.js | 4 ++++ client/coral-framework/services/store.js | 6 ++++++ 11 files changed, 70 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/services/notification.js b/client/coral-admin/src/services/notification.js index 7ad85692b..aca5bdc80 100644 --- a/client/coral-admin/src/services/notification.js +++ b/client/coral-admin/src/services/notification.js @@ -1,3 +1,8 @@ +/** + * createNotificationService returns a notification services based on toast. + * @param {Object} toast + * @return {Object} notification service + */ export function createNotificationService(toast) { return { success(msg) { diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 70fb9fa50..ac94d8b29 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -38,7 +38,17 @@ const getAuthToken = (store, storage) => { return null; }; -export function createContext({reducers = {}, pluginsConfig = [], graphqlExtension = {}, notification}) { +/** + * createContext setups and returns Talk dependencies that should be + * passed to `TalkProvider`. + * @param {Object} [config] configuration + * @param {Object} [config.reducers] extra reducers to add to redux + * @param {Array} [config.pluginsConfig] plugin configuration as returned by importing pluginsConfig + * @param {Object} [config.graphqlExtensions] additional extension to the graphql framework + * @param {Object} [config.notification] replace default notification service + * @return {Object} context + */ +export function createContext({reducers = {}, pluginsConfig = [], graphqlExtension = {}, notification} = {}) { const protocol = location.protocol === 'https:' ? 'wss' : 'ws'; const eventEmitter = new EventEmitter({wildcard: true}); const storage = createStorage(); diff --git a/client/coral-framework/services/client.js b/client/coral-framework/services/client.js index ce83d501f..5907488e3 100644 --- a/client/coral-framework/services/client.js +++ b/client/coral-framework/services/client.js @@ -15,8 +15,16 @@ function resolveToken(token) { return typeof token === 'function' ? token() : token; } +/** + * createClient setups and returns an Apollo GraphQL Client + * @param {Object} [options] configuration + * @param {string|function} [options.token] auth token + * @param {string} [options.uri] uri of the graphql server + * @param {string} [options.liveUri] uri of the graphql subscription server + * @return {Object} apollo client + */ export function createClient(options = {}) { - const {token, uri, liveUri, ...apolloOptions} = options; + const {token, uri, liveUri} = options; const wsClient = new SubscriptionClient(liveUri, { reconnect: true, lazy: true, @@ -53,7 +61,6 @@ export function createClient(options = {}) { ); const client = new ApolloClient({ - ...apolloOptions, connectToDevTools: true, addTypename: true, fragmentMatcher: new IntrospectionFragmentMatcher({introspectionQueryResultData}), diff --git a/client/coral-framework/services/events.js b/client/coral-framework/services/events.js index f6a62763d..e1b13afd9 100644 --- a/client/coral-framework/services/events.js +++ b/client/coral-framework/services/events.js @@ -1,3 +1,9 @@ +/** + * createReduxEmitter returns a redux middleware proxying redux actions to + * the event emitter + * @param {Object} eventEmitter + * @return {function} redux middleware + */ export function createReduxEmitter(eventEmitter) { return () => (next) => (action) => { diff --git a/client/coral-framework/services/graphqlRegistry.js b/client/coral-framework/services/graphqlRegistry.js index 5ca549183..938bf7f78 100644 --- a/client/coral-framework/services/graphqlRegistry.js +++ b/client/coral-framework/services/graphqlRegistry.js @@ -268,6 +268,11 @@ class GraphQLRegistry { } } +/** + * createGraphQLRegistry + * @param {Function} getSlotFragments A callback with signature `(slot, part) => [documents]` to retrieve slot fragments. + * @return {Object} graphql registry + */ export function createGraphQLRegistry(getSlotFragments) { return new GraphQLRegistry(getSlotFragments); } diff --git a/client/coral-framework/services/history.js b/client/coral-framework/services/history.js index f64bb8fb1..c80d4b920 100644 --- a/client/coral-framework/services/history.js +++ b/client/coral-framework/services/history.js @@ -1,6 +1,11 @@ import {browserHistory} from 'react-router'; import {useBasename} from 'history'; +/** + * createHistory returns the history service for react router + * @param {string} basename base path of the url + * @return {Object} histor service + */ export function createHistory(basename) { if (!basename) { return browserHistory; diff --git a/client/coral-framework/services/notification.js b/client/coral-framework/services/notification.js index fa0e61b3f..5730200ad 100644 --- a/client/coral-framework/services/notification.js +++ b/client/coral-framework/services/notification.js @@ -1,3 +1,8 @@ +/** + * createNotificationService returns a notification services based on pym. + * @param {Object} pym + * @return {Object} notification service + */ export function createNotificationService(pym) { return { success(msg) { diff --git a/client/coral-framework/services/plugins.js b/client/coral-framework/services/plugins.js index 5474e919f..1aae0c662 100644 --- a/client/coral-framework/services/plugins.js +++ b/client/coral-framework/services/plugins.js @@ -174,6 +174,11 @@ class PluginsService { } } -export function createPluginsService(plugins) { - return new PluginsService(plugins); +/** + * createPluginsService returns a plugins service. + * @param {Array} plugins config as returned from importing `pluginsConfig` + * @return {Object} plugins service + */ +export function createPluginsService(pluginsConfig) { + return new PluginsService(pluginsConfig); } diff --git a/client/coral-framework/services/rest.js b/client/coral-framework/services/rest.js index f879659ca..e5f9e5e09 100644 --- a/client/coral-framework/services/rest.js +++ b/client/coral-framework/services/rest.js @@ -43,6 +43,13 @@ const handleResp = (res) => { } }; +/** + * createRestClient setups and returns a Rest Client + * @param {Object} options configuration + * @param {string} options.uri uri of the rest server + * @param {string|function} [options.token] auth token + * @return {Object} rest client + */ export function createRestClient(options) { const {token, uri} = options; const client = (path, options) => { diff --git a/client/coral-framework/services/storage.js b/client/coral-framework/services/storage.js index 1454d2ac5..9f06595fa 100644 --- a/client/coral-framework/services/storage.js +++ b/client/coral-framework/services/storage.js @@ -34,6 +34,10 @@ function getStorage(type) { return storage; } +/** + * createStorage returns a localStorage wrapper if available + * @return {Object} localStorage wrapper + */ export function createStorage() { return getStorage('localStorage'); } diff --git a/client/coral-framework/services/store.js b/client/coral-framework/services/store.js index e5fc52503..3ccfe9e2f 100644 --- a/client/coral-framework/services/store.js +++ b/client/coral-framework/services/store.js @@ -1,5 +1,11 @@ import {createStore as reduxCreateStore, combineReducers, applyMiddleware, compose} from 'redux'; +/** + * createStore creates a Redux Store + * @param {Object} reducers addtional reducers + * @param {Array} [middlewares] additional middlewares + * @return {Object} redux store + */ export function createStore(reducers, middlewares = []) { const enhancers = [ applyMiddleware(