Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!this.handlers) {
throw new Error('fusion-plugin-rpc requires `handlers`');
}
if (!this.handlers[method]) {
throw new MissingHandlerError(method);
}
return this.handlers[method](args);
}
}
const plugin: RPCPluginType = createPlugin({
deps: {
handlers: RPCHandlersToken,
// $FlowFixMe
emitter: UniversalEventsToken.optional,
},
provides: ({handlers} = {}) => {
return {from: () => new RPC(handlers)};
},
});
export default plugin;
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,
Provider: RouterProviderToken.optional,
},
middleware: ({emitter, Provider = DefaultProvider}, self) => {
return async (ctx, next) => {
const prefix = ctx.prefix || '';
if (!ctx.element) {
return next();
}
const myAPI = self.from(ctx);
if (__NODE__) {
let pageData = {
title: ctx.path,
page: ctx.path,
};
const context = {
action: null,
const pluginFactory: () => PluginType = () =>
createPlugin({
deps: {
loader: I18nLoaderToken.optional,
events: UniversalEventsToken.optional,
},
provides: ({loader, events}) => {
class I18n {
translations: TranslationsObjectType;
locale: string | Locale;
emitter: ?IEmitter;
constructor(ctx) {
if (!loader) {
loader = createLoader();
}
const {translations, locale} = loader.from(ctx);
this.emitter = events && events.from(ctx);
this.translations = translations;
this.locale = locale;
}
const pluginFactory: () => PluginType = () =>
createPlugin({
deps: {
fetch: FetchToken.optional,
hydrationState: HydrationStateToken.optional,
events: UniversalEventsToken.optional,
},
provides: ({fetch = window.fetch, hydrationState, events} = {}) => {
class I18n {
locale: string;
translations: TranslationsObjectType;
requestedKeys: Set;
constructor() {
const {localeCode, translations} =
hydrationState || loadTranslations();
this.requestedKeys = new Set();
this.translations = translations || {};
if (localeCode) {
this.locale = localeCode;
}
}