getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Rollback or Cancel behaviour #51

Open taras opened 11 years ago

taras commented 11 years ago

I have a cancel button in an edit view and I'd like to cancel all changes when that button is pressed.

Do I manipulate the session or the model to rollback the changes?

c0urg3tt3 commented 11 years ago

you can have a look at the shadow of session as described in comment of this issue https://github.com/GroupTalent/epf/issues/22

taras commented 11 years ago

@c0urg3tt3 works, is this how it should be done going forward?

ghempton commented 11 years ago

I am probably going to add a rollback method to session at some point. But the more idiomatic way to do this is to use a child session (e.g. session.newSession()). To cancel all the changes that have taken place in a child session you can just opt to never call flush.

jasonkriss commented 11 years ago

We use childSession when we have a dedicated edit view but as far as I can tell there are some situations where using a childSession isn't possible. For example, we have a customer profile page that allows a user to edit the name and other attributes in place without having to first click an edit button. If the user escapes from the input while editing, we need to rollback. I'm not sure how this would be done using a childSession.

ghempton commented 11 years ago

@jasonkriss this is partially why the current behavior for childSessions is to flush into the parent session immediately. In your profile case you could create a child session upon edit and simply flush when they click save.