Skip to content

Instantly share code, notes, and snippets.

@ghempton
Created April 29, 2014 02:00
Show Gist options
  • Save ghempton/11389065 to your computer and use it in GitHub Desktop.
Save ghempton/11389065 to your computer and use it in GitHub Desktop.
Transactional Route
`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