Skip to content

Commit

Permalink
fix(api): rename preload (#7)
Browse files Browse the repository at this point in the history
Make the name of the static component preload more explicit, so developers understand what it is they are preloading when reading code
  • Loading branch information
adam-26 committed Feb 24, 2018
2 parents 5957d06 + 65b8c48 commit 93104ef
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -374,7 +374,7 @@ class MyComponent extends React.Component {
};

onMouseOver = () => {
BarChunk.preload();
BarChunk.preloadChunk();
};

render() {
Expand Down Expand Up @@ -729,14 +729,14 @@ Props passed to this component will be passed straight through to the
wrapped component, in additional to a `chunk` prop that includes all data required for rendering the imported resources.
### Common `chunk` and `chunks` static methods
#### `preload()`
#### `preloadChunk()`
This is a static method that can be used to load the component ahead of time.
```js
const ChunkComponent = chunk({...});

ChunkComponent.preload();
ChunkComponent.preloadChunk();
```
This returns a promise, but you should avoid waiting for that promise to
Expand Down
6 changes: 3 additions & 3 deletions __tests__/__snapshots__/test.js.snap
Expand Up @@ -77,21 +77,21 @@ exports[`chunk loading success 4`] = `
</div>
`;

exports[`chunk preload 1`] = `
exports[`chunk preloadChunk 1`] = `
<div>
MyLoadingComponent
{"isLoading":true,"hasLoaded":false,"pastDelay":false,"timedOut":false,"error":null,"loaded":null,"importKeys":[]}
</div>
`;

exports[`chunk preload 2`] = `
exports[`chunk preloadChunk 2`] = `
<div>
MyComponent
{"prop":"bar"}
</div>
`;

exports[`chunk preload 3`] = `
exports[`chunk preloadChunk 3`] = `
<div>
MyComponent
{"prop":"baz"}
Expand Down
8 changes: 4 additions & 4 deletions __tests__/test.js
Expand Up @@ -246,10 +246,10 @@ describe('chunk', () => {
expect(component.toJSON()).toMatchSnapshot(); // serverside
});

test('preload', async () => {
test('preloadChunk', async () => {
let ChunkMyComponent = chunk(createLoader(400, () => MyComponent))(SingleImport);

let promise = ChunkMyComponent.preload();
let promise = ChunkMyComponent.preloadChunk();
await waitFor(200);

let component1 = renderer.create(<ChunkMyComponent prop="bar" />);
Expand Down Expand Up @@ -366,14 +366,14 @@ describe('chunk', () => {
}
});

test('throws on static `preload()`', async () => {
test('throws on static `preloadChunk()`', async () => {
let ChunkMyComponent = chunk(createLoader(400, () => { throw new Error('import err'); }), {
hoistStatics: true
})();

expect.assertions(1);
try {
await ChunkMyComponent.preload();
await ChunkMyComponent.preloadChunk();
} catch (e) {
expect(e.message).toEqual('import err');
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -190,7 +190,7 @@ function createChunkComponent(loadFn, options) {
})
};

static preload() {
static preloadChunk() {
return init(true);
}

Expand Down

0 comments on commit 93104ef

Please sign in to comment.