Replace etype and eid instance variables with accessors
authorFrank Bessou <frank.bessou@logilab.fr>
Tue, 02 May 2017 10:22:17 +0200
changeset 148 8c0ca4705fab
parent 147 62686dc26af0
child 149 ac11d4378e29
Replace etype and eid instance variables with accessors
src/components/Entity.js
--- a/src/components/Entity.js	Thu Apr 27 16:01:14 2017 +0200
+++ b/src/components/Entity.js	Tue May 02 10:22:17 2017 +0200
@@ -162,8 +162,6 @@
 
     constructor(props) {
         super(props);
-        this.etype = props.match.params.etype;
-        this.eid = props.match.params.eid;
         this.state = {entity: null};
         this.getEditionSchema = this.getEditionSchema.bind(this);
         this.updateEntity = this.updateEntity.bind(this);
@@ -172,8 +170,16 @@
         this.navigateToSelf = this.navigateToSelf.bind(this);
     }
 
+    getEType() {
+        return this.props.match.params.etype;
+    }
+
+    getEID() {
+        return this.props.match.params.eid;
+    }
+
     componentDidMount() {
-        Api.getEntity(this.etype, this.eid)
+        Api.getEntity(this.getEType(), this.getEID())
             .then(
                 (entity) => {
                     this.setState({entity: entity});
@@ -187,7 +193,7 @@
     }
 
     deleteEntity() {
-        Api.deleteEntity(this.etype, this.eid)
+        Api.deleteEntity(this.getEType(), this.getEID())
             .then( () => {
                 this.navigateToParent();
             });
@@ -216,7 +222,9 @@
             return <div>loading...</div>;
         }
         if (this.props.match.params.view === 'edit') {
-            const redirectPath = `/${this.etype}/${this.eid}`;
+            const etype = this.getEType();
+            const eid = this.getEID();
+            const redirectPath = `/${etype}/${eid}`;
             return (
                 <EntityEditForm {...this.props}
                     entity={this.state.entity}