File tree Expand file tree Collapse file tree 5 files changed +23
-22
lines changed
Expand file tree Collapse file tree 5 files changed +23
-22
lines changed Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ You need to instruct your snapshot solution to save state of `loadable-component
334334For example, to do this with [ ` react-snap ` ] ( https://github.com/stereobooster/react-snap ) you can use following code:
335335
336336``` js
337- import { getState } from ' loadable-components/snap '
337+ import { getState } from ' loadable-components'
338338
339339// Set up for react-snap.
340340window .snapSaveState = () => getState ()
Original file line number Diff line number Diff line change 11/* eslint-env browser */
22/* eslint-disable import/prefer-default-export */
3- import { getAll as getAllComponents } from '.. /componentTracker'
4- import { LOADABLE_STATE } from '.. /constants'
3+ import { getAll as getAllComponents } from './componentTracker'
4+ import { LOADABLE_STATE } from './constants'
55
6- export function getState ( ) {
6+ function getState ( ) {
77 const componentByIds = getAllComponents ( )
88 const children = Object . keys ( componentByIds ) . reduce ( ( ids , id ) => {
99 const component = componentByIds [ id ]
@@ -12,3 +12,5 @@ export function getState() {
1212 } , [ ] )
1313 return { [ LOADABLE_STATE ] : { children } }
1414}
15+
16+ export default getState
Original file line number Diff line number Diff line change 1+ import { getState } from './'
2+ import loadable from './loadable'
3+
4+ describe ( '#getState' , ( ) => {
5+ it ( 'should return only loaded components' , ( ) => {
6+ const getComponent = jest . fn ( ( ) => import ( './__fixtures__/Dummy' ) )
7+ const Loadable = loadable ( getComponent , {
8+ modules : [ './__fixtures__/Dummy' ] ,
9+ } )
10+ expect ( getState ( ) ) . toEqual ( { __LOADABLE_STATE__ : { children : [ ] } } )
11+ Loadable . load ( )
12+ expect ( getState ( ) ) . toEqual ( {
13+ __LOADABLE_STATE__ : { children : [ { id : './__fixtures__/Dummy' } ] } ,
14+ } )
15+ } )
16+ } )
Original file line number Diff line number Diff line change 11import * as tracker from './componentTracker'
22
33export { default as loadComponents } from './loadComponents'
4+ export { default as getState } from './getState'
45export { LOADABLE } from './constants'
56export { default } from './loadable'
67export const componentTracker = tracker
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments