How to use fusion-plugin-universal-events - 4 common examples

To help you get started, we’ve selected a few fusion-plugin-universal-events examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fusionjs / fusionjs / fusion-plugin-rpc / src / mock.js View on Github external
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;
github fusionjs / fusionjs / fusion-plugin-react-router / src / plugin.js View on Github external
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,
github fusionjs / fusionjs / fusion-plugin-i18n / src / node.js View on Github external
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;
        }
github fusionjs / fusionjs / fusion-plugin-i18n / src / browser.js View on Github external
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;
          }
        }

fusion-plugin-universal-events

Events Emitter

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis

Popular fusion-plugin-universal-events functions

Similar packages