Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.

Commit 6d20216

Browse files
author
Ian Wensink
committed
style
1 parent b409dca commit 6d20216

File tree

12 files changed

+183
-184
lines changed

12 files changed

+183
-184
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"semantic-release": "semantic-release",
5151
"test": "yarn test:unit && yarn test:lint",
5252
"test:unit": "jest --coverage",
53-
"test:update": "yarn test:unit -- -u",
53+
"test:unit:update": "yarn test:unit -- -u",
5454
"test:lint": "prettier 'src/**/*.js' -l && tslint 'src/**/*.js'",
5555
"format": "prettier 'src/**/*.js' --write -l && tslint 'src/**/*.js' --fix"
5656
},

src/components/EntityListMapper.test.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import renderer from 'react-test-renderer';
44
import site from '../utils/site';
55
import waitForHnData from '../utils/waitForHnData';
6-
import { mapper, asyncMapper } from '../utils/tests';
6+
import { uuid, mapper, asyncMapper } from '../utils/tests';
77

88
jest.mock('../utils/site', () => {
99
return require('../utils/tests').mockSite();
@@ -21,10 +21,7 @@ beforeEach(() => {
2121
describe('EntityListMapper', async () => {
2222
test('with required props, same bundle', async () => {
2323
const component = (
24-
<EntityListMapper
25-
entities={['unique-uuid', 'unique-uuid-2']}
26-
mapper={mapper}
27-
/>
24+
<EntityListMapper entities={[uuid, 'unique-uuid-2']} mapper={mapper} />
2825
);
2926

3027
expect(renderer.create(component).toJSON()).toMatchSnapshot();
@@ -36,10 +33,7 @@ describe('EntityListMapper', async () => {
3633

3734
test('with required props, different bundle', async () => {
3835
const component = (
39-
<EntityListMapper
40-
entities={['unique-uuid', 'unique-uuid-3']}
41-
mapper={mapper}
42-
/>
36+
<EntityListMapper entities={[uuid, 'unique-uuid-3']} mapper={mapper} />
4337
);
4438

4539
expect(renderer.create(component).toJSON()).toMatchSnapshot();
@@ -52,7 +46,7 @@ describe('EntityListMapper', async () => {
5246
test('non-existing entity', async () => {
5347
const component = (
5448
<EntityListMapper
55-
entities={['unique-uuid', 'non-existing-entity']}
49+
entities={[uuid, 'non-existing-entity']}
5650
mapper={mapper}
5751
/>
5852
);
@@ -67,7 +61,7 @@ describe('EntityListMapper', async () => {
6761
test('with all props', async () => {
6862
const component = (
6963
<EntityListMapper
70-
entities={['unique-uuid', 'unique-uuid-3']}
64+
entities={[uuid, 'unique-uuid-3']}
7165
entityProps={{ testEntityProp: true }}
7266
entityWrapper={'main'}
7367
mapper={mapper}
@@ -84,7 +78,7 @@ describe('EntityListMapper', async () => {
8478
test('asyncMapper', async () => {
8579
const component = (
8680
<EntityListMapper
87-
entities={['unique-uuid', 'unique-uuid-3']}
81+
entities={[uuid, 'unique-uuid-3']}
8882
entityProps={{ testEntityProp: true }}
8983
entityWrapper={'main'}
9084
mapper={asyncMapper}

src/components/EntityMapper.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class EntityMapper extends Component {
3939
}
4040

4141
// Make sure there is an entityComponent.
42-
if (!entityComponent) return;
42+
if (!entityComponent) {
43+
return;
44+
}
4345

4446
// If it has a .default (ES6+), use that.
4547
if (entityComponent.default) {
@@ -48,9 +50,9 @@ class EntityMapper extends Component {
4850

4951
// Store the entityComponent globally, so it can be rendered sync.
5052
EntityMapper.entityComponents.push({
51-
uuid,
52-
mapper,
5353
component: entityComponent,
54+
mapper,
55+
uuid,
5456
});
5557
}
5658

@@ -88,7 +90,9 @@ class EntityMapper extends Component {
8890
).componentState,
8991
);
9092

91-
if (state) return true;
93+
if (state) {
94+
return true;
95+
}
9296

9397
this.context.hnContext.state.entities.push({
9498
componentState: await this.loadComponent({
@@ -134,10 +138,12 @@ class EntityMapper extends Component {
134138

135139
async loadComponent({ uuid, mapper, asyncMapper, entityProps }) {
136140
// Check if component for combination of mapper + uuid already was loaded
137-
const entityComponent = EntityMapper.entityComponents.find(c => c.mapper === mapper && c.uuid === uuid);
141+
const entityComponent = EntityMapper.entityComponents.find(
142+
c => c.mapper === mapper && c.uuid === uuid,
143+
);
138144

139145
// If component isn't loaded yet, go load it
140-
if(!entityComponent) {
146+
if (!entityComponent) {
141147
this.setState({ ready: false });
142148

143149
await EntityMapper.assureComponent({
@@ -167,12 +173,20 @@ class EntityMapper extends Component {
167173

168174
const entity = site.getData(uuid);
169175

170-
if (!entity) return null;
176+
if (!entity) {
177+
return null;
178+
}
171179

172-
const EntityComponent = getNested(() =>
173-
EntityMapper.entityComponents.find(c => c.uuid === uuid && c.mapper === mapper).component);
180+
const EntityComponent = getNested(
181+
() =>
182+
EntityMapper.entityComponents.find(
183+
c => c.uuid === uuid && c.mapper === mapper,
184+
).component,
185+
);
174186

175-
if (!EntityComponent) return null;
187+
if (!EntityComponent) {
188+
return null;
189+
}
176190

177191
return (
178192
<EntityComponent

src/components/EntityMapper.test.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import renderer from 'react-test-renderer';
44
import site from '../utils/site';
55
import waitForHnData from '../utils/waitForHnData';
6-
import { mapper, asyncMapper } from '../utils/tests';
6+
import { uuid, mapper, asyncMapper } from '../utils/tests';
77

88
jest.mock('../utils/site', () => {
99
return require('../utils/tests').mockSite();
@@ -20,12 +20,7 @@ beforeEach(() => {
2020

2121
describe('EntityMapper', async () => {
2222
test('with required props', async () => {
23-
const component = (
24-
<EntityMapper
25-
uuid={'unique-uuid'}
26-
mapper={mapper}
27-
/>
28-
);
23+
const component = <EntityMapper uuid={uuid} mapper={mapper} />;
2924

3025
expect(renderer.create(component).toJSON()).toMatchSnapshot();
3126

@@ -36,10 +31,7 @@ describe('EntityMapper', async () => {
3631

3732
test('non-existing entity', async () => {
3833
const component = (
39-
<EntityMapper
40-
uuid={'non-existing-entity'}
41-
mapper={mapper}
42-
/>
34+
<EntityMapper uuid={'non-existing-entity'} mapper={mapper} />
4335
);
4436

4537
expect(renderer.create(component).toJSON()).toMatchSnapshot();
@@ -51,11 +43,7 @@ describe('EntityMapper', async () => {
5143

5244
test('with required props & asyncMapper', async () => {
5345
const component = (
54-
<EntityMapper
55-
uuid={'unique-uuid'}
56-
mapper={asyncMapper}
57-
asyncMapper
58-
/>
46+
<EntityMapper uuid={uuid} mapper={asyncMapper} asyncMapper />
5947
);
6048

6149
expect(renderer.create(component).toJSON()).toMatchSnapshot();
@@ -69,7 +57,7 @@ describe('EntityMapper', async () => {
6957
const component = (
7058
<EntityMapper
7159
entityProps={{ testEntityProp: true }}
72-
uuid={'unique-uuid'}
60+
uuid={uuid}
7361
mapper={mapper}
7462
/>
7563
);
@@ -85,7 +73,7 @@ describe('EntityMapper', async () => {
8573
const component = (
8674
<EntityMapper
8775
entityProps={{ testEntityProp: true }}
88-
uuid={'unique-uuid'}
76+
uuid={uuid}
8977
mapper={asyncMapper}
9078
asyncMapper
9179
/>

src/components/__snapshots__/DrupalPage.test.js.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ exports[`DrupalPage with all props 2`] = `
1616
Object {
1717
"__hn": Object {
1818
"entity": Object {
19-
"bundle": "unique_bundle",
20-
"type": "unique_type",
19+
"bundle": "unique_bundle_1",
20+
"type": "unique_type_1",
2121
},
2222
},
2323
}
@@ -26,14 +26,14 @@ exports[`DrupalPage with all props 2`] = `
2626
url="/"
2727
>
2828
<div
29-
bundle="unique_type__unique_bundle"
29+
bundle="unique_type_1__unique_bundle_1"
3030
className="MyCustomMapperComponent"
3131
entity={
3232
Object {
3333
"__hn": Object {
3434
"entity": Object {
35-
"bundle": "unique_bundle",
36-
"type": "unique_type",
35+
"bundle": "unique_bundle_1",
36+
"type": "unique_type_1",
3737
},
3838
},
3939
}
@@ -42,8 +42,8 @@ exports[`DrupalPage with all props 2`] = `
4242
Object {
4343
"__hn": Object {
4444
"entity": Object {
45-
"bundle": "unique_bundle",
46-
"type": "unique_type",
45+
"bundle": "unique_bundle_1",
46+
"type": "unique_type_1",
4747
},
4848
},
4949
}
@@ -52,8 +52,8 @@ exports[`DrupalPage with all props 2`] = `
5252
Object {
5353
"__hn": Object {
5454
"entity": Object {
55-
"bundle": "unique_bundle",
56-
"type": "unique_type",
55+
"bundle": "unique_bundle_1",
56+
"type": "unique_type_1",
5757
},
5858
},
5959
}
@@ -67,14 +67,14 @@ exports[`DrupalPage with required props 1`] = `null`;
6767

6868
exports[`DrupalPage with required props 2`] = `
6969
<div
70-
bundle="unique_type__unique_bundle"
70+
bundle="unique_type_1__unique_bundle_1"
7171
className="MyCustomMapperComponent"
7272
entity={
7373
Object {
7474
"__hn": Object {
7575
"entity": Object {
76-
"bundle": "unique_bundle",
77-
"type": "unique_type",
76+
"bundle": "unique_bundle_1",
77+
"type": "unique_type_1",
7878
},
7979
},
8080
}
@@ -83,8 +83,8 @@ exports[`DrupalPage with required props 2`] = `
8383
Object {
8484
"__hn": Object {
8585
"entity": Object {
86-
"bundle": "unique_bundle",
87-
"type": "unique_type",
86+
"bundle": "unique_bundle_1",
87+
"type": "unique_type_1",
8888
},
8989
},
9090
}
@@ -93,8 +93,8 @@ exports[`DrupalPage with required props 2`] = `
9393
Object {
9494
"__hn": Object {
9595
"entity": Object {
96-
"bundle": "unique_bundle",
97-
"type": "unique_type",
96+
"bundle": "unique_bundle_1",
97+
"type": "unique_type_1",
9898
},
9999
},
100100
}

0 commit comments

Comments
 (0)