Add some docs

This commit is contained in:
Chi Vinh Le
2017-08-24 18:40:38 +07:00
parent c2b0a60d8a
commit 645aaa09ae
11 changed files with 70 additions and 5 deletions
@@ -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) {
+11 -1
View File
@@ -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();
+9 -2
View File
@@ -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}),
@@ -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) => {
@@ -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);
}
@@ -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;
@@ -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) {
+7 -2
View File
@@ -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);
}
+7
View File
@@ -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) => {
@@ -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');
}
+6
View File
@@ -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(