Skip to content

Commit

Permalink
feat(api): Change static loader method name
Browse files Browse the repository at this point in the history
This _should_ be a breaking change - but the package was released 1 hour ago and has no downloads, just release it as a minor change.
  • Loading branch information
adam-26 committed Feb 24, 2018
1 parent 3e3264a commit cdded47
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
16 changes: 10 additions & 6 deletions README.md
Expand Up @@ -15,9 +15,10 @@ _Code splitting with minimal boiler plate_

_This is a fork of [react-loadable](https://github.com/jamiebuilds/react-loadable), differences and new features include:_
* _A modified API to support new features_
* _Full render control using a HOC wrapped component_
* _Improved re-use of import components_
* _Improved support for route code splitting_
* _Preloading all chunks required to render an entire route_
* _Pre-loading all chunks required to render an entire route_
* _Option to _hoist_ static methods of imported components_
* _Option to enable retry support with backoff_
* _Manually invoking a retry after timeout or error_
Expand Down Expand Up @@ -195,6 +196,8 @@ best for your app.

Its often useful to assign _names_ to webpack chunks. This can be achieved easily using inline code comments.

Be aware that naming chunks **impacts how webpack bundles your code**. You should [read about webpack code splitting](https://webpack.js.org/guides/code-splitting/#dynamic-imports).

```js
import { chunk, chunks } from 'react-chunk';

Expand Down Expand Up @@ -402,8 +405,8 @@ const FooChunk = chunk(() => import('./Foo'))();
const BarChunk = chunk(() => import('./Bar'))();

preloadChunks([
FooChunk.getLoader(),
BarChunk.getLoader(),
FooChunk.getChunkLoader(),
BarChunk.getChunkLoader(),
]).then(() => {
// use 'setState()' to render using the loaded components
}).catch(err => {
Expand Down Expand Up @@ -741,14 +744,14 @@ resolve to update your UI. In most cases it creates a bad user experience.
[Read more about preloading](#preloading).
#### `getLoader()`
#### `getChunkLoader()`
This is a static method that can be used to obtain a reference to the components loader. It should be used in conjuntion with [preloadChunks()](#preloadchunks)
```js
const ChunkComponent = chunk({...});

ChunkComponent.getLoader();
ChunkComponent.getChunkLoader();
```
Expand Down Expand Up @@ -1152,10 +1155,11 @@ res.send(`
</head>
<body>
<div id="app">${html}</div>
<script src="/dist/main.js"></script>
<script src="/dist/manifest.js"></script>
${scripts.map(script => {
return `<script src="/dist/${script.file}"></script>`
}).join('\n')}
<script src="/dist/main.js"></script>
</body>
</html>
`);
Expand Down
6 changes: 3 additions & 3 deletions __tests__/test.js
Expand Up @@ -359,7 +359,7 @@ describe('chunk', () => {

expect.assertions(1);
try {
await preloadChunks([ChunkMyComponent.getLoader()]);
await preloadChunks([ChunkMyComponent.getChunkLoader()]);
} catch (e) {
expect(e.message).toEqual('import err');
}
Expand All @@ -383,7 +383,7 @@ describe('chunk', () => {
MyComponent.myStatic = jestFn;
let ChunkMyComponent = chunk(createLoader(400, () => MyComponent), { hoist: true })();

await preloadChunks([ChunkMyComponent.getLoader()]);
await preloadChunks([ChunkMyComponent.getChunkLoader()]);

expect(ChunkMyComponent.myStatic).toBe(jestFn);
delete MyComponent.myStatic;
Expand Down Expand Up @@ -550,7 +550,7 @@ test('preloadChunks', async () => {
let LoadableMyComponent = chunk(createLoader(300, () => MyComponent))(SingleImport);
let LoadableMapComponent = chunks({ MyComponent: createLoader(300, () => MyComponent) })(MapImport);

const loaders = [LoadableMyComponent.getLoader(), LoadableMapComponent.getLoader()];
const loaders = [LoadableMyComponent.getChunkLoader(), LoadableMapComponent.getChunkLoader()];

await preloadChunks(loaders);

Expand Down
6 changes: 3 additions & 3 deletions example/components/PreLoadButton.js
Expand Up @@ -18,9 +18,9 @@ export default class PreLoadButton extends React.Component {

// Verify webpack only submits a single request
preloadChunks([
ContentChunk.getLoader(),
ContentChunk.getLoader(),
ContentChunk.getLoader()
ContentChunk.getChunkLoader(),
ContentChunk.getChunkLoader(),
ContentChunk.getChunkLoader()
]).then(() => {
console.log('pre-loading modules');
this.setState({ isLoaded: true });
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -194,7 +194,7 @@ function createChunkComponent(loadFn, options) {
return init(true);
}

static getLoader() {
static getChunkLoader() {
return init;
}

Expand Down

0 comments on commit cdded47

Please sign in to comment.