Skip to content

Commit 3445bea

Browse files
committed
fix(snapshot): fix snap usage
Closes #40
1 parent 0abf679 commit 3445bea

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ You need to instruct your snapshot solution to save state of `loadable-component
334334
For 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.
340340
window.snapSaveState = () => getState()
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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

src/getState.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
})

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as tracker from './componentTracker'
22

33
export { default as loadComponents } from './loadComponents'
4+
export { default as getState } from './getState'
45
export { LOADABLE } from './constants'
56
export { default } from './loadable'
67
export const componentTracker = tracker

src/snap/index.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)