Created
April 29, 2014 02:00
-
-
Save ghempton/11389065 to your computer and use it in GitHub Desktop.
Transactional Route
This file contains 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
`import Route from 'outreach/core/route'` | |
# Route which manages a transaction on it's content. | |
# E.g. when the route is exited, the transaction will | |
# be rolled back | |
class TransactionalRoute extends Route | |
resolveSession: (parentSession) -> | |
@session = parentSession.newSession() | |
exit: -> | |
super() | |
# TODO destroy the session | |
actions: | |
willTransition: (transition) -> | |
isDirty = @currentModel.diff(@session.getShadow(@currentModel)).length > 0 | |
if isDirty && !transition.data.confirmed | |
transition.abort() | |
promise = @dialogManager.confirm | |
title: "Cancel Edit" | |
message: "Are you sure you want to leave this page? There are unsaved changes." | |
promise.then -> | |
transition.data.confirmed = true | |
transition.retry() | |
`export default TransactionalRoute` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment