Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/* eslint-env browser */
import {createPlugin, createToken} from 'fusion-core';
import type {Token} from 'fusion-core';
import type {ErrorHandlerPluginType} from './types.js';
export const ErrorHandlingEmitterToken: Token = createToken(
'ErrorHandlingEmitterToken'
);
const plugin =
__BROWSER__ &&
createPlugin({
deps: {emit: ErrorHandlingEmitterToken.optional},
provides: ({emit}) => {
let _emit =
emit ||
((e, src) => {
if (window.onerror) window.onerror(e.message, src, null, null, e);
});
if (__DEV__) {
let oldEmit = _emit;
_emit = (e, src) => {
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import React from 'react';
import {createToken, type Context, type Token} from 'fusion-core';
import type {ApolloClient} from 'apollo-client';
import {GraphQLOptions} from 'apollo-server-koa';
export type InitApolloClientType = (
ctx: Context,
initialState: TInitialState
) => ApolloClient;
// We should have better flow types for the schema
export const GraphQLSchemaToken: Token = createToken('GraphQlSchemaToken');
export type ApolloContext = Context => T | T;
export const ApolloContextToken: Token> = createToken(
'ApolloContextToken'
);
export const ApolloCacheContext = React.createContext();
export const GraphQLEndpointToken: Token = createToken(
'GraphQLEndpointToken'
);
export const ApolloClientToken: Token<
InitApolloClientType
> = createToken('ApolloClientToken');
import React from 'react';
import {createToken, type Context, type Token} from 'fusion-core';
import type {ApolloClient} from 'apollo-client';
import {GraphQLOptions} from 'apollo-server-koa';
export type InitApolloClientType = (
ctx: Context,
initialState: TInitialState
) => ApolloClient;
// We should have better flow types for the schema
export const GraphQLSchemaToken: Token = createToken('GraphQlSchemaToken');
export type ApolloContext = Context => T | T;
export const ApolloContextToken: Token> = createToken(
'ApolloContextToken'
);
export const ApolloCacheContext = React.createContext();
export const GraphQLEndpointToken: Token = createToken(
'GraphQLEndpointToken'
);
export const ApolloClientToken: Token<
InitApolloClientType
> = createToken('ApolloClientToken');
export const GetDataFromTreeToken: Token = createToken(
'GetDataFromTreeToken'
);
type ProviderPropsType = {
history: RouterHistoryType,
children?: React.Node,
};
type HistoryWrapperType = {
from: (
ctx: Context
) => {
history: RouterHistoryType,
},
};
export const RouterProviderToken: Token<
React.ComponentType
> = createToken('RouterProvider');
export const RouterToken: Token = createToken('Router');
const Router = __NODE__ ? ServerRouter : BrowserRouter;
type PluginDepsType = {
emitter: typeof UniversalEventsToken.optional,
Provider: typeof RouterProviderToken.optional,
};
// Preserve browser history instance across HMR
let browserHistory;
const plugin: FusionPlugin = createPlugin({
deps: {
emitter: UniversalEventsToken.optional,
test('collectDependencyData', () => {
const app = new App();
const V = createToken('V');
const A = createToken('A');
const B = createToken('B');
const C = createToken('C');
const APlugin = createPlugin({});
const BPlugin = createPlugin({deps: {a: A}});
const CPlugin = createPlugin({
provides() {
return 1;
},
});
app.register(V, null);
app.register(A, APlugin);
app.register(B, BPlugin);
app.register(C, CPlugin);
app.enhance(C, () => 2);
const data = collectDependencyData(app);
export function getService(
appCreator: () => FusionApp,
plugin: FusionPlugin
): TService {
const app = appCreator();
const token: Token = createToken('service-helper');
let extractedService = null;
app.register(token, plugin);
app.register(
createPlugin({
deps: {service: token},
provides: ({service}) => {
extractedService = service;
},
})
);
app.resolve();
if (!extractedService) {
throw new Error('Provided plugin does not export a service');
}
import {createToken} from 'fusion-core';
import type {Token} from 'fusion-core';
import type {GetInitialStateType, ReactReduxServiceType} from './types.js';
export const ReduxToken: Token = createToken(
'ReduxToken'
);
export const ReducerToken: Token> = createToken('ReducerToken');
export const PreloadedStateToken: Token = createToken(
'PreloadedStateToken'
);
export const EnhancerToken: Token> = createToken(
'EnhancerToken'
);
export const GetInitialStateToken: Token> = createToken(
'GetInitialStateToken'
);
(message: string, callback: LogCallback): Logger,
(message: string, meta: any, callback: LogCallback): Logger,
(message: string, ...meta: any[]): Logger,
(infoObject: Object): Logger,
};
export type Logger = {
log: LogMethod,
error: LeveledLogMethod,
warn: LeveledLogMethod,
info: LeveledLogMethod,
verbose: LeveledLogMethod,
debug: LeveledLogMethod,
silly: LeveledLogMethod,
};
export const LoggerToken: Token = createToken('LoggerToken');
import {createToken} from 'fusion-core';
import type {FusionPlugin, Token} from 'fusion-core';
import serverPlugin from './node';
import clientPlugin, {HydrationStateToken} from './browser';
import createI18nLoader from './loader';
import type {
I18nDepsType,
I18nServiceType,
TranslationsObjectType,
TranslateFuncType,
} from './types.js';
import {I18nLoaderToken} from './tokens.js';
const I18nToken: Token = createToken('I18nToken');
const plugin: FusionPlugin = __NODE__
? serverPlugin
: clientPlugin;
export type {
I18nDepsType,
I18nServiceType,
TranslationsObjectType,
TranslateFuncType,
};
export default plugin;
export {I18nToken, I18nLoaderToken, HydrationStateToken, createI18nLoader};
*
* @flow
*/
import type {Reducer, StoreEnhancer} from 'redux';
import {createToken} from 'fusion-core';
import type {Token} from 'fusion-core';
import type {GetInitialStateType, ReactReduxServiceType} from './types.js';
export const ReduxToken: Token = createToken(
'ReduxToken'
);
export const ReducerToken: Token> = createToken('ReducerToken');
export const PreloadedStateToken: Token = createToken(
'PreloadedStateToken'
);
export const EnhancerToken: Token> = createToken(
'EnhancerToken'
);
export const GetInitialStateToken: Token> = createToken(
'GetInitialStateToken'
);