Last active
January 18, 2019 15:06
-
-
Save yohanmishkin/cb4cff0a51f58f0b233baab2164b07fb to your computer and use it in GitHub Desktop.
Ember component composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Component.extend({ | |
metrics: service(), | |
propTypes: { | |
eventName, | |
eventTrackingId, | |
eventTrackingProperty, | |
eventSource, | |
potentialVisitor | |
}, | |
approve: task(function* () { | |
yield this.potentialVisitor.approve(); | |
this._track('appprove'); | |
}), | |
deny: task(function* () { | |
yield this.potentialVisitor.deny(); | |
this._track('deny'); | |
}), | |
_track(command) { | |
this.metrics.trackEvent(this.eventName, { | |
command, | |
[this.eventTrackingProperty]: this.eventTrackingId, | |
source: this.eventSource | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Component.extend({ | |
flashMessages: service(), | |
propTypes: { | |
approveTask: PropTypes.instanceOf(TaskInstance), | |
denyTask: PropTypes.instanceOf(TaskInstance), | |
}, | |
approve: task(function* () { | |
try{ | |
yield this.approveTask(); | |
this.flashMessages.showAndHideFlash('success', this.successfulApprovalMessage) | |
} catch (error) { | |
this.flashMessages.showAndHideFlash( | |
'error', | |
this.failedApprovalMessage, | |
parseErrorForDisplay(error) | |
); | |
} | |
}), | |
deny: task(function* () { | |
try{ | |
yield this.denyTask(); | |
this.flashMessages.showAndHideFlash('success', 'Access denied'); | |
} catch (error) { | |
this.flashMessages.showAndHideFlash( | |
'error', | |
this.failedDenialMessage, | |
parseErrorForDisplay(error) | |
); | |
} | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Controller.extend({ | |
approveEntryTask: task(function* { | |
yield this.entry.approveEntry(); | |
yield get(this.entry, 'flow.badge'); | |
yield this.entry.reload(); | |
}), | |
denyEntryTask: task(function*() { | |
yield this.entry.denyEntry(); | |
yield this.entry.reload(); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment