From 12361a4e78c07ad7d0891c1a8653c6f44c308c0f Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Fri, 1 Sep 2017 02:12:04 +0300 Subject: [PATCH 1/6] fix($server): Add global modules cache Add global modules cache to replace per-component one in the future commits --- src/requireUniversalModule.js | 14 +++++++++----- src/utils.js | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index ee8b221..d80eed2 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -27,6 +27,7 @@ declare var __webpack_modules__: Object export const CHUNK_NAMES = new Set() export const MODULE_IDS = new Set() +export const MODULES: Map = new Map() export default function requireUniversalModule( universalConfig: Config | ConfigFunc, @@ -75,6 +76,7 @@ export default function requireUniversalModule( props, context, modCache, + MODULES, true ) } @@ -115,7 +117,8 @@ export default function requireUniversalModule( chunkName, props, context, - modCache + modCache, + MODULES ) if (exp) return res(exp) @@ -208,10 +211,11 @@ const getConfig = ( : universalConfig } - const load: Load = typeof universalConfig === 'function' - ? universalConfig - : // $FlowIssue - () => universalConfig + const load: Load = + typeof universalConfig === 'function' + ? universalConfig + : // $FlowIssue + () => universalConfig return { file: 'default', diff --git a/src/utils.js b/src/utils.js index 67b9c45..225a81c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,8 +9,9 @@ export const babelInterop = (mod: ?Mod) => mod && typeof mod === 'object' && mod.__esModule ? mod.default : mod export const DefaultLoading = () =>
Loading...
-export const DefaultError = ({ error }: { error: Object }) => +export const DefaultError = ({ error }: { error: Object }) => (
Error: {error && error.message}
+) export const tryRequire = (id: Id): ?any => { try { @@ -37,6 +38,7 @@ export const resolveExport = ( props: Object, context: Object, modCache: Object, + modGlobalCache: Map, isSync?: boolean = false ) => { const exp = findExport(mod, key) @@ -45,6 +47,9 @@ export const resolveExport = ( const info = { isServer, isSync } onLoad(mod, info, props, context) } + if (chunkName) { + modGlobalCache.set(callForString(chunkName, props), mod) + } if (chunkName && exp) cacheExport(exp, chunkName, props, modCache) return exp } @@ -61,11 +66,13 @@ export const findExport = (mod: ?Mod, key?: Key): ?any => { } export const createElement = (Component: any, props: {}) => - React.isValidElement(Component) - ? React.cloneElement(Component, props) - : + React.isValidElement(Component) ? ( + React.cloneElement(Component, props) + ) : ( + + ) -export const callForString = (strFun: StrFun, props: Object) => +export const callForString = (strFun: StrFun, props: Object): string => typeof strFun === 'function' ? strFun(props) : strFun export const loadFromCache = ( From 0c68c5cbf18e49f443ff9acd25a9c36d9decf4db Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Tue, 5 Sep 2017 01:23:12 +0300 Subject: [PATCH 2/6] fix($server): onLoad function triggers only once on server Fix when onLoad function triggers only once on server by adding global onLoad functions cache and flushing it when flushChunkNames and flushChunkIds is called. Also, per-component modCache replaced with global MODULES cache as there is no need to store them per component after calling onLoad logic changed https://github.com/faceyspacey/react-universal-component/issues/30 --- __tests__/index.js | 13 ++++- __tests__/requireUniversalModule.js | 9 +++- __tests__/utils.js | 10 ++-- src/flowTypes.js | 1 - src/index.js | 1 - src/requireUniversalModule.js | 78 ++++++++++++++++++----------- src/utils.js | 32 ++++-------- 7 files changed, 84 insertions(+), 60 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index b948f2b..491e125 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -4,7 +4,11 @@ import React from 'react' import renderer from 'react-test-renderer' import universal from '../src' -import { flushModuleIds, flushChunkNames } from '../src/requireUniversalModule' +import { + flushModuleIds, + flushChunkNames, + clearModulesCache +} from '../src/requireUniversalModule' import { createApp, @@ -28,6 +32,11 @@ import { dynamicBabelNodeComponent } from '../__test-helpers__' +beforeEach(() => { + // clear because callForString values are not unique in each case + clearModulesCache() +}) + describe('async lifecycle', () => { it('loading', async () => { const asyncComponent = createComponent(40, MyComponent) @@ -252,7 +261,7 @@ describe('other options', () => { expect(component.toJSON()).toMatchSnapshot() // success }) - it('key (function): resolves export to function return', async () => { + it.only('key (function): resolves export to function return', async () => { const asyncComponent = createComponent(20, { fooKey: MyComponent }) const Component = universal(asyncComponent, { key: module => module.fooKey diff --git a/__tests__/requireUniversalModule.js b/__tests__/requireUniversalModule.js index 363a61f..b393fe3 100644 --- a/__tests__/requireUniversalModule.js +++ b/__tests__/requireUniversalModule.js @@ -4,11 +4,16 @@ import { createPath, waitFor, normalizePath } from '../__test-helpers__' import req, { flushModuleIds, - flushChunkNames + flushChunkNames, + clearModulesCache } from '../src/requireUniversalModule' const requireModule = (asyncImport, options, props) => - req(asyncImport, { ...options, modCache: {}, promCache: {} }, props) + req(asyncImport, { ...options, promCache: {} }, props) + +beforeEach(() => { + clearModulesCache() +}) describe('requireSync: tries to require module synchronously on both the server and client', () => { it('babel', () => { diff --git a/__tests__/utils.js b/__tests__/utils.js index 152a49c..e635ddb 100644 --- a/__tests__/utils.js +++ b/__tests__/utils.js @@ -56,17 +56,21 @@ test('requireById: requires module for babel or webpack depending on environment expect(() => requireById('/foo')).toThrow() }) -test('resolveExport: finds export and calls onLoad', () => { +test('resolveExport: calls onLoad and updates caches', () => { const onLoad = jest.fn() const mod = { foo: 'bar' } const props = { baz: 123 } const context = {} - const exp = resolveExport(mod, 'foo', onLoad, undefined, props, context) - expect(exp).toEqual('bar') + const modules = new Map() + const onLoadCache = new Map() + + resolveExport(mod, onLoad, 'test', props, context, modules, onLoadCache) const info = { isServer: false, isSync: false } expect(onLoad).toBeCalledWith(mod, info, props, context) + expect(modules.get('test')).toEqual(mod) + expect(onLoadCache.get(mod).has(onLoad)).toEqual(true) // todo: test caching }) diff --git a/src/flowTypes.js b/src/flowTypes.js index db787a2..70cbf81 100644 --- a/src/flowTypes.js +++ b/src/flowTypes.js @@ -35,7 +35,6 @@ export type ModuleOptions = { onLoad?: OnLoad, alwaysUpdate?: boolean, isDynamic: boolean, - modCache: Object, promCache: Object, id?: string } diff --git a/src/index.js b/src/index.js index 721d8e7..8c68376 100644 --- a/src/index.js +++ b/src/index.js @@ -43,7 +43,6 @@ export default function universal( const isDynamic = hasBabelPlugin || testBabelPlugin options.isDynamic = isDynamic - options.modCache = {} options.promCache = {} return class UniversalComponent extends React.Component { diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index d80eed2..99f951f 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -6,7 +6,8 @@ import type { Config, ConfigFunc, Props, - Load + Load, + OnLoad } from './flowTypes' import { @@ -14,9 +15,9 @@ import { tryRequire, resolveExport, callForString, - loadFromCache, loadFromPromiseCache, - cacheProm + cacheProm, + findExport } from './utils' export const IS_TEST = process.env.NODE_ENV === 'test' @@ -28,6 +29,7 @@ declare var __webpack_modules__: Object export const CHUNK_NAMES = new Set() export const MODULE_IDS = new Set() export const MODULES: Map = new Map() +export const ON_LOAD_CALLBACKS: Map> = new Map() export default function requireUniversalModule( universalConfig: Config | ConfigFunc, @@ -41,7 +43,6 @@ export default function requireUniversalModule( onLoad, onError, isDynamic, - modCache, promCache } = options @@ -50,11 +51,9 @@ export default function requireUniversalModule( const asyncOnly = !path && !resolve const requireSync = (props: Object, context: Object): ?any => { - let exp = loadFromCache(chunkName, props, modCache) - - if (!exp) { - let mod + let mod = MODULES.get(callForString(chunkName, props)) + if (!mod) { if (!isWebpack() && path) { const modulePath = callForString(path, props) || '' mod = tryRequire(modulePath) @@ -66,28 +65,39 @@ export default function requireUniversalModule( mod = tryRequire(weakId) } } - - if (mod) { - exp = resolveExport( - mod, - key, - onLoad, - chunkName, - props, - context, - modCache, - MODULES, - true - ) - } } - return exp + if (!mod) return + + resolveExport( + mod, + onLoad, + chunkName, + props, + context, + MODULES, + ON_LOAD_CALLBACKS, + true + ) + + return findExport(mod, key) } const requireAsync = (props: Object, context: Object): Promise => { - const exp = loadFromCache(chunkName, props, modCache) - if (exp) return Promise.resolve(exp) + const cachedMod = MODULES.get(callForString(chunkName, props)) + if (cachedMod) { + // in case if called with new onLoad function + resolveExport( + cachedMod, + onLoad, + chunkName, + props, + context, + MODULES, + ON_LOAD_CALLBACKS + ) + return Promise.resolve(findExport(cachedMod, key)) + } const cachedPromise = loadFromPromiseCache(chunkName, props, promCache) if (cachedPromise) return cachedPromise @@ -110,16 +120,17 @@ export default function requireUniversalModule( const resolve = mod => { clearTimeout(timer) - const exp = resolveExport( + resolveExport( mod, - key, onLoad, chunkName, props, context, - modCache, - MODULES + MODULES, + ON_LOAD_CALLBACKS ) + + const exp = mod && findExport(mod, key) if (exp) return res(exp) reject(new Error('export not found')) @@ -190,15 +201,24 @@ export default function requireUniversalModule( export const flushChunkNames = (): Ids => { const chunks = Array.from(CHUNK_NAMES) CHUNK_NAMES.clear() + // do not clear MODULES as they won't change + ON_LOAD_CALLBACKS.clear() return chunks } export const flushModuleIds = (): Ids => { const ids = Array.from(MODULE_IDS) MODULE_IDS.clear() + // do not clear MODULES as they won't change + ON_LOAD_CALLBACKS.clear() return ids } +// for test purpose +export const clearModulesCache = () => { + MODULES.clear() +} + const getConfig = ( isDynamic: ?boolean, universalConfig: Config | ConfigFunc, diff --git a/src/utils.js b/src/utils.js index 225a81c..9aecd73 100644 --- a/src/utils.js +++ b/src/utils.js @@ -32,26 +32,27 @@ export const requireById = (id: Id): ?any => { export const resolveExport = ( mod: ?Mod, - key: ?Key, onLoad: ?OnLoad, chunkName: ?StrFun, props: Object, context: Object, - modCache: Object, modGlobalCache: Map, + onLoadGlobalCache: Map>, isSync?: boolean = false ) => { - const exp = findExport(mod, key) - if (onLoad && mod) { + if (chunkName) { + modGlobalCache.set(callForString(chunkName, props), mod) + } + if (mod && !onLoadGlobalCache.has(mod)) { + onLoadGlobalCache.set(mod, new Set()) + } + const onLoadModCache = onLoadGlobalCache.get(mod) + if (onLoad && onLoadModCache && !onLoadModCache.has(onLoad)) { const isServer = typeof window === 'undefined' const info = { isServer, isSync } onLoad(mod, info, props, context) + onLoadModCache.add(onLoad) } - if (chunkName) { - modGlobalCache.set(callForString(chunkName, props), mod) - } - if (chunkName && exp) cacheExport(exp, chunkName, props, modCache) - return exp } export const findExport = (mod: ?Mod, key?: Key): ?any => { @@ -75,19 +76,6 @@ export const createElement = (Component: any, props: {}) => export const callForString = (strFun: StrFun, props: Object): string => typeof strFun === 'function' ? strFun(props) : strFun -export const loadFromCache = ( - chunkName: StrFun, - props: Object, - modCache: Object -) => modCache[callForString(chunkName, props)] - -export const cacheExport = ( - exp: any, - chunkName: StrFun, - props: Object, - modCache: Object -) => (modCache[callForString(chunkName, props)] = exp) - export const loadFromPromiseCache = ( chunkName: StrFun, props: Object, From 925ef2abd2ff5702c29b0ba6ede7cd1283697a54 Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Tue, 5 Sep 2017 22:38:57 +0300 Subject: [PATCH 3/6] fix($server): revert previous changes --- __tests__/index.js | 13 +---- __tests__/requireUniversalModule.js | 9 +--- __tests__/utils.js | 10 ++-- src/flowTypes.js | 1 + src/index.js | 1 + src/requireUniversalModule.js | 77 ++++++++++------------------- src/utils.js | 32 +++++++----- 7 files changed, 56 insertions(+), 87 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index 491e125..b948f2b 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -4,11 +4,7 @@ import React from 'react' import renderer from 'react-test-renderer' import universal from '../src' -import { - flushModuleIds, - flushChunkNames, - clearModulesCache -} from '../src/requireUniversalModule' +import { flushModuleIds, flushChunkNames } from '../src/requireUniversalModule' import { createApp, @@ -32,11 +28,6 @@ import { dynamicBabelNodeComponent } from '../__test-helpers__' -beforeEach(() => { - // clear because callForString values are not unique in each case - clearModulesCache() -}) - describe('async lifecycle', () => { it('loading', async () => { const asyncComponent = createComponent(40, MyComponent) @@ -261,7 +252,7 @@ describe('other options', () => { expect(component.toJSON()).toMatchSnapshot() // success }) - it.only('key (function): resolves export to function return', async () => { + it('key (function): resolves export to function return', async () => { const asyncComponent = createComponent(20, { fooKey: MyComponent }) const Component = universal(asyncComponent, { key: module => module.fooKey diff --git a/__tests__/requireUniversalModule.js b/__tests__/requireUniversalModule.js index b393fe3..363a61f 100644 --- a/__tests__/requireUniversalModule.js +++ b/__tests__/requireUniversalModule.js @@ -4,16 +4,11 @@ import { createPath, waitFor, normalizePath } from '../__test-helpers__' import req, { flushModuleIds, - flushChunkNames, - clearModulesCache + flushChunkNames } from '../src/requireUniversalModule' const requireModule = (asyncImport, options, props) => - req(asyncImport, { ...options, promCache: {} }, props) - -beforeEach(() => { - clearModulesCache() -}) + req(asyncImport, { ...options, modCache: {}, promCache: {} }, props) describe('requireSync: tries to require module synchronously on both the server and client', () => { it('babel', () => { diff --git a/__tests__/utils.js b/__tests__/utils.js index e635ddb..152a49c 100644 --- a/__tests__/utils.js +++ b/__tests__/utils.js @@ -56,21 +56,17 @@ test('requireById: requires module for babel or webpack depending on environment expect(() => requireById('/foo')).toThrow() }) -test('resolveExport: calls onLoad and updates caches', () => { +test('resolveExport: finds export and calls onLoad', () => { const onLoad = jest.fn() const mod = { foo: 'bar' } const props = { baz: 123 } const context = {} - const modules = new Map() - const onLoadCache = new Map() - - resolveExport(mod, onLoad, 'test', props, context, modules, onLoadCache) + const exp = resolveExport(mod, 'foo', onLoad, undefined, props, context) + expect(exp).toEqual('bar') const info = { isServer: false, isSync: false } expect(onLoad).toBeCalledWith(mod, info, props, context) - expect(modules.get('test')).toEqual(mod) - expect(onLoadCache.get(mod).has(onLoad)).toEqual(true) // todo: test caching }) diff --git a/src/flowTypes.js b/src/flowTypes.js index 70cbf81..db787a2 100644 --- a/src/flowTypes.js +++ b/src/flowTypes.js @@ -35,6 +35,7 @@ export type ModuleOptions = { onLoad?: OnLoad, alwaysUpdate?: boolean, isDynamic: boolean, + modCache: Object, promCache: Object, id?: string } diff --git a/src/index.js b/src/index.js index 8c68376..721d8e7 100644 --- a/src/index.js +++ b/src/index.js @@ -43,6 +43,7 @@ export default function universal( const isDynamic = hasBabelPlugin || testBabelPlugin options.isDynamic = isDynamic + options.modCache = {} options.promCache = {} return class UniversalComponent extends React.Component { diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index 99f951f..6e1f54b 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -6,8 +6,7 @@ import type { Config, ConfigFunc, Props, - Load, - OnLoad + Load } from './flowTypes' import { @@ -15,9 +14,9 @@ import { tryRequire, resolveExport, callForString, + loadFromCache, loadFromPromiseCache, - cacheProm, - findExport + cacheProm } from './utils' export const IS_TEST = process.env.NODE_ENV === 'test' @@ -28,8 +27,6 @@ declare var __webpack_modules__: Object export const CHUNK_NAMES = new Set() export const MODULE_IDS = new Set() -export const MODULES: Map = new Map() -export const ON_LOAD_CALLBACKS: Map> = new Map() export default function requireUniversalModule( universalConfig: Config | ConfigFunc, @@ -43,6 +40,7 @@ export default function requireUniversalModule( onLoad, onError, isDynamic, + modCache, promCache } = options @@ -51,9 +49,11 @@ export default function requireUniversalModule( const asyncOnly = !path && !resolve const requireSync = (props: Object, context: Object): ?any => { - let mod = MODULES.get(callForString(chunkName, props)) + let exp = loadFromCache(chunkName, props, modCache) + + if (!exp) { + let mod - if (!mod) { if (!isWebpack() && path) { const modulePath = callForString(path, props) || '' mod = tryRequire(modulePath) @@ -65,39 +65,27 @@ export default function requireUniversalModule( mod = tryRequire(weakId) } } - } - if (!mod) return - - resolveExport( - mod, - onLoad, - chunkName, - props, - context, - MODULES, - ON_LOAD_CALLBACKS, - true - ) + if (mod) { + exp = resolveExport( + mod, + key, + onLoad, + chunkName, + props, + context, + modCache, + true + ) + } + } - return findExport(mod, key) + return exp } const requireAsync = (props: Object, context: Object): Promise => { - const cachedMod = MODULES.get(callForString(chunkName, props)) - if (cachedMod) { - // in case if called with new onLoad function - resolveExport( - cachedMod, - onLoad, - chunkName, - props, - context, - MODULES, - ON_LOAD_CALLBACKS - ) - return Promise.resolve(findExport(cachedMod, key)) - } + const exp = loadFromCache(chunkName, props, modCache) + if (exp) return Promise.resolve(exp) const cachedPromise = loadFromPromiseCache(chunkName, props, promCache) if (cachedPromise) return cachedPromise @@ -120,17 +108,15 @@ export default function requireUniversalModule( const resolve = mod => { clearTimeout(timer) - resolveExport( + const exp = resolveExport( mod, + key, onLoad, chunkName, props, context, - MODULES, - ON_LOAD_CALLBACKS + modCache ) - - const exp = mod && findExport(mod, key) if (exp) return res(exp) reject(new Error('export not found')) @@ -201,24 +187,15 @@ export default function requireUniversalModule( export const flushChunkNames = (): Ids => { const chunks = Array.from(CHUNK_NAMES) CHUNK_NAMES.clear() - // do not clear MODULES as they won't change - ON_LOAD_CALLBACKS.clear() return chunks } export const flushModuleIds = (): Ids => { const ids = Array.from(MODULE_IDS) MODULE_IDS.clear() - // do not clear MODULES as they won't change - ON_LOAD_CALLBACKS.clear() return ids } -// for test purpose -export const clearModulesCache = () => { - MODULES.clear() -} - const getConfig = ( isDynamic: ?boolean, universalConfig: Config | ConfigFunc, diff --git a/src/utils.js b/src/utils.js index 9aecd73..ff87610 100644 --- a/src/utils.js +++ b/src/utils.js @@ -32,27 +32,22 @@ export const requireById = (id: Id): ?any => { export const resolveExport = ( mod: ?Mod, + key: ?Key, onLoad: ?OnLoad, chunkName: ?StrFun, props: Object, context: Object, - modGlobalCache: Map, - onLoadGlobalCache: Map>, + modCache: Object, isSync?: boolean = false ) => { - if (chunkName) { - modGlobalCache.set(callForString(chunkName, props), mod) - } - if (mod && !onLoadGlobalCache.has(mod)) { - onLoadGlobalCache.set(mod, new Set()) - } - const onLoadModCache = onLoadGlobalCache.get(mod) - if (onLoad && onLoadModCache && !onLoadModCache.has(onLoad)) { + const exp = findExport(mod, key) + if (onLoad && mod) { const isServer = typeof window === 'undefined' const info = { isServer, isSync } onLoad(mod, info, props, context) - onLoadModCache.add(onLoad) } + if (chunkName && exp) cacheExport(exp, chunkName, props, modCache) + return exp } export const findExport = (mod: ?Mod, key?: Key): ?any => { @@ -73,9 +68,22 @@ export const createElement = (Component: any, props: {}) => ) -export const callForString = (strFun: StrFun, props: Object): string => +export const callForString = (strFun: StrFun, props: Object) => typeof strFun === 'function' ? strFun(props) : strFun +export const loadFromCache = ( + chunkName: StrFun, + props: Object, + modCache: Object +) => modCache[callForString(chunkName, props)] + +export const cacheExport = ( + exp: any, + chunkName: StrFun, + props: Object, + modCache: Object +) => (modCache[callForString(chunkName, props)] = exp) + export const loadFromPromiseCache = ( chunkName: StrFun, props: Object, From ea0dd8a25debfdeecf2c1f9006a9d44749031645 Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Tue, 5 Sep 2017 23:09:57 +0300 Subject: [PATCH 4/6] fix($server): disable caching on the server requireSync https://github.com/faceyspacey/react-universal-component/issues/30 --- src/requireUniversalModule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index 6e1f54b..cd3e9c0 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -51,7 +51,7 @@ export default function requireUniversalModule( const requireSync = (props: Object, context: Object): ?any => { let exp = loadFromCache(chunkName, props, modCache) - if (!exp) { + if (!exp || isServer) { let mod if (!isWebpack() && path) { From c45fa5fee50d3fe73f63ab7542a12240a5ebb7f0 Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Thu, 7 Sep 2017 13:31:54 +0300 Subject: [PATCH 5/6] fix($server): disable loadFromCache from the server --- src/requireUniversalModule.js | 2 +- src/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index cd3e9c0..6e1f54b 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -51,7 +51,7 @@ export default function requireUniversalModule( const requireSync = (props: Object, context: Object): ?any => { let exp = loadFromCache(chunkName, props, modCache) - if (!exp || isServer) { + if (!exp) { let mod if (!isWebpack() && path) { diff --git a/src/utils.js b/src/utils.js index ff87610..c290799 100644 --- a/src/utils.js +++ b/src/utils.js @@ -75,7 +75,7 @@ export const loadFromCache = ( chunkName: StrFun, props: Object, modCache: Object -) => modCache[callForString(chunkName, props)] +) => !isServer && modCache[callForString(chunkName, props)] export const cacheExport = ( exp: any, From 69b42f396b4ac3a43f97f9578db1dd3c88da7ccc Mon Sep 17 00:00:00 2001 From: Eldar Gamisoniya Date: Thu, 7 Sep 2017 13:57:52 +0300 Subject: [PATCH 6/6] style: remove additional formatting --- src/requireUniversalModule.js | 9 ++++----- src/utils.js | 11 ++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/requireUniversalModule.js b/src/requireUniversalModule.js index 6e1f54b..ee8b221 100644 --- a/src/requireUniversalModule.js +++ b/src/requireUniversalModule.js @@ -208,11 +208,10 @@ const getConfig = ( : universalConfig } - const load: Load = - typeof universalConfig === 'function' - ? universalConfig - : // $FlowIssue - () => universalConfig + const load: Load = typeof universalConfig === 'function' + ? universalConfig + : // $FlowIssue + () => universalConfig return { file: 'default', diff --git a/src/utils.js b/src/utils.js index c290799..22fdee9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,9 +9,8 @@ export const babelInterop = (mod: ?Mod) => mod && typeof mod === 'object' && mod.__esModule ? mod.default : mod export const DefaultLoading = () =>
Loading...
-export const DefaultError = ({ error }: { error: Object }) => ( +export const DefaultError = ({ error }: { error: Object }) =>
Error: {error && error.message}
-) export const tryRequire = (id: Id): ?any => { try { @@ -62,11 +61,9 @@ export const findExport = (mod: ?Mod, key?: Key): ?any => { } export const createElement = (Component: any, props: {}) => - React.isValidElement(Component) ? ( - React.cloneElement(Component, props) - ) : ( - - ) + React.isValidElement(Component) + ? React.cloneElement(Component, props) + : export const callForString = (strFun: StrFun, props: Object) => typeof strFun === 'function' ? strFun(props) : strFun