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

Commit a08a994

Browse files
author
Ian Wensink
committed
fix(entity-mapper): make entityProps stateful
1 parent 4ae05e2 commit a08a994

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/EntityMapper.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ class EntityMapper extends Component {
5151

5252
static getBundle = entity => getNested(() => `${entity.__hn.entity.type}__${entity.__hn.entity.bundle}`, '_fallback');
5353

54-
state = {
55-
entityComponentSymbol: null,
56-
ready: false,
57-
uuid: null,
58-
page: null,
59-
};
54+
constructor(props) {
55+
super(props);
56+
57+
this.state = {
58+
entityComponentSymbol: null,
59+
ready: false,
60+
uuid: props.uuid,
61+
entityProps: props.entityProps,
62+
};
63+
}
6064

6165
componentDidMount() {
6266
this.loadComponent(this.props);
@@ -68,19 +72,19 @@ class EntityMapper extends Component {
6872
}
6973
}
7074

71-
async loadComponent({ uuid, page, mapper, asyncMapper }) {
75+
async loadComponent({ uuid, mapper, asyncMapper, entityProps }) {
7276
this.setState({ ready: false });
7377
const entityComponentSymbol = await EntityMapper.assureComponent({ uuid, mapper, asyncMapper });
74-
this.setState({ uuid, page, entityComponentSymbol, ready: true });
78+
this.setState({ uuid, entityComponentSymbol, ready: true, entityProps });
7579
}
7680

7781
isReady() {
7882
return this.state.ready;
7983
}
8084

8185
render() {
82-
const { index, entityProps, paragraphProps } = this.props;
83-
const { page, uuid, entityComponentSymbol } = this.state;
86+
const { index, paragraphProps } = this.props;
87+
const { uuid, entityComponentSymbol, entityProps } = this.state;
8488

8589
const entity = site.getData(uuid);
8690

@@ -93,7 +97,6 @@ class EntityMapper extends Component {
9397
return (
9498
<Component
9599
bundle={EntityMapper.getBundle(entity)}
96-
page={page}
97100
paragraph={entity}
98101
entity={entity}
99102
index={index}

0 commit comments

Comments
 (0)