Move event handler assignment into method

This commit is contained in:
2018-04-15 20:49:17 +02:00
parent 89d6b920b1
commit a04ab09ed6
2 changed files with 24 additions and 22 deletions
+4 -1
View File
@@ -19,6 +19,9 @@ export default Route.extend({
}, },
afterModel() { afterModel() {
return this.get('kredits').loadContributorsAndProposals(); return this.get('kredits').loadContributorsAndProposals()
.then(() => {
this.get('kredits').addContractEventHandlers();
});
} }
}); });
+6 -7
View File
@@ -88,7 +88,11 @@ export default Service.extend({
}).then(({ contributors, proposals }) => { }).then(({ contributors, proposals }) => {
this.set('contributors', contributors); this.set('contributors', contributors);
this.set('proposals', proposals); this.set('proposals', proposals);
}).then(() => { });
},
addContractEventHandlers() {
// Operator events
this.get('kredits').Operator this.get('kredits').Operator
.on('ProposalCreated', (proposalId) => { .on('ProposalCreated', (proposalId) => {
this.handleProposalCreated(proposalId); this.handleProposalCreated(proposalId);
@@ -100,11 +104,11 @@ export default Service.extend({
this.handleProposalExecuted(proposalId, contributorId, amount); this.handleProposalExecuted(proposalId, contributorId, amount);
}); });
// Token events
this.get('kredits').Token this.get('kredits').Token
.on('Transfer', (from, to, value) => { .on('Transfer', (from, to, value) => {
this.handleTransfer(from, to, value); this.handleTransfer(from, to, value);
}); });
});
}, },
// TODO: Only assign valid attributes // TODO: Only assign valid attributes
@@ -112,11 +116,6 @@ export default Service.extend({
debug('[kredits] build', name, attributes); debug('[kredits] build', name, attributes);
let model = getOwner(this).lookup(`model:${name}`); let model = getOwner(this).lookup(`model:${name}`);
// coerce id to string
if (attributes.id) {
attributes.id = attributes.id.toString();
}
model.setProperties(attributes); model.setProperties(attributes);
return model; return model;
}, },