How to use the fusion-core.memoize function in fusion-core

To help you get started, we’ve selected a few fusion-core 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-react-redux / src / server.js View on Github external
await getInitialState(this.ctx)
            );
          }
          const enhancers = [enhancer, ctxEnhancer(this.ctx)].filter(Boolean);
          // $FlowFixMe
          this.store = createStore(
            reducer,
            preloadedState,
            // $FlowFixMe
            compose(...enhancers)
          );
          return this.store;
        }
      }
      return {
        from: memoize(ctx => new Redux(ctx)),
      };
    },
    middleware(_, redux) {
github fusionjs / fusionjs / fusion-test-utils / src / __tests__ / index.js View on Github external
provides: () => {
        return {
          from: memoize(ctx => {
            return 5;
          }),
        };
      },
      middleware: (deps, self) => {
github fusionjs / fusionjs / fusion-plugin-i18n / src / node.js View on Github external
const template = this.translations[key];

          if (typeof template !== 'string') {
            this.emitter && this.emitter.emit('i18n-translate-miss', {key});
            return key;
          }

          return template.replace(/\${(.*?)}/g, (_, k) =>
            interpolations[k] === void 0
              ? '${' + k + '}'
              : String(interpolations[k])
          );
        }
      }

      const service = {from: memoize(ctx => new I18n(ctx))};
      return service;
    },
    middleware: (_, plugin) => {
github fusionjs / fusionjs / create-fusion-plugin / templates / plugin / content / src / server.js View on Github external
provides() {
      class PluginLogic {
        ctx: Context;
        value: ?string;

        constructor(ctx) {
          this.ctx = ctx;
          this.value = null;
        }
        async init() {
          this.value = '__plugin__value__';
          return this.value;
        }
      }
      return {
        from: memoize(ctx => new PluginLogic(ctx)),
      };
    },
    middleware(_, myPlugin) {
github fusionjs / fusionjs / fusion-plugin-universal-events / src / server.js View on Github external
constructor() {
    super();
    this.from = memoize(ctx => {
      return new ScopedEmitter(ctx, this);
    });
  }
  emit(type: mixed, payload: mixed, ctx?: Context): void {
github fusionjs / fusionjs / fusion-plugin-i18n / src / loader.js View on Github external
};
  const root = './translations';
  const locales = readDir(root)
    .filter(p => p.match(/json$/))
    .map(p => p.replace(/\.json$/, ''));
  const data = locales.reduce((memo, locale) => {
    const parsedLocale = new Locale(locale);
    memo[parsedLocale.normalized] = JSON.parse(
      fs.readFileSync(path.join(root, locale + '.json'), 'utf8')
    );
    return memo;
  }, {});
  const supportedLocales = new Locales(locales);

  return {
    from: memoize(ctx => {
      const expectedLocales = new Locales(resolveLocales(ctx));
      const locale = expectedLocales.best(supportedLocales);
      const translations: TranslationsObjectType = data[locale.normalized];
      return {translations, locale};
    }),
  };
};
github fusionjs / fusionjs / fusion-plugin-rpc / src / server.js View on Github external
provides: deps => {
      const {emitter, handlers} = deps;

      const service = {
        from: memoize(ctx => new RPC(emitter, handlers, ctx)),
      };
      return service;
    },
github fusionjs / fusionjs / fusion-plugin-react-router / src / plugin.js View on Github external
provides() {
    return {
      from: memoize(() => {
        const api: {history: RouterHistoryType} = ({
          history: null,
        }: any);
        return api;
      }),
    };
  },
});
github fusionjs / fusionjs / fusion-plugin-jwt / src / jwt-server.js View on Github external
provides: deps => {
      const {secret, cookieName, expires = 86400} = deps;
      const service: SessionService = {
        from: memoize((ctx: Context) => {
          return new JWTSession(ctx, {secret, cookieName, expires});
        }),
      };
      return service;
    },
    middleware: (deps, service) => {
github fusionjs / fusion-cli / plugins / critical-chunk-ids-plugin.js View on Github external
provides: () => {
    return {
      from: memoize(() => {
        const chunkIds = new Set();
        for (const chunkId of initialChunkIds) {
          chunkIds.add(chunkId);
        }
        return new Set();
      }),
    };
  },
});