Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
provides: () => {
return {
from: memoize(ctx => {
return 5;
}),
};
},
middleware: (deps, self) => {
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) => {
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) {
constructor() {
super();
this.from = memoize(ctx => {
return new ScopedEmitter(ctx, this);
});
}
emit(type: mixed, payload: mixed, ctx?: Context): void {
};
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};
}),
};
};
provides: deps => {
const {emitter, handlers} = deps;
const service = {
from: memoize(ctx => new RPC(emitter, handlers, ctx)),
};
return service;
},
provides() {
return {
from: memoize(() => {
const api: {history: RouterHistoryType} = ({
history: null,
}: any);
return api;
}),
};
},
});
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) => {
provides: () => {
return {
from: memoize(() => {
const chunkIds = new Set();
for (const chunkId of initialChunkIds) {
chunkIds.add(chunkId);
}
return new Set();
}),
};
},
});