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
334
334
For example, to do this with [ ` react-snap ` ] ( https://github.com/stereobooster/react-snap ) you can use following code:
335
335
336
336
``` js
337
- import { getState } from ' loadable-components/snap '
337
+ import { getState } from ' loadable-components'
338
338
339
339
// Set up for react-snap.
340
340
window .snapSaveState = () => getState ()
Original file line number Diff line number Diff line change 1
1
/* eslint-env browser */
2
2
/* 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'
5
5
6
- export function getState ( ) {
6
+ function getState ( ) {
7
7
const componentByIds = getAllComponents ( )
8
8
const children = Object . keys ( componentByIds ) . reduce ( ( ids , id ) => {
9
9
const component = componentByIds [ id ]
@@ -12,3 +12,5 @@ export function getState() {
12
12
} , [ ] )
13
13
return { [ LOADABLE_STATE ] : { children } }
14
14
}
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 1
1
import * as tracker from './componentTracker'
2
2
3
3
export { default as loadComponents } from './loadComponents'
4
+ export { default as getState } from './getState'
4
5
export { LOADABLE } from './constants'
5
6
export { default } from './loadable'
6
7
export const componentTracker = tracker
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments