Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS#revert should ignore omitted fields #205

Closed
awhitty opened this issue Aug 27, 2015 · 7 comments
Closed

DS#revert should ignore omitted fields #205

awhitty opened this issue Aug 27, 2015 · 7 comments

Comments

@awhitty
Copy link

awhitty commented Aug 27, 2015

Just as the title says. The docs say:

Synchronously revert the state of an item to the last time it was saved via an async adapter. Returns the reverted item.

I know it can be interpreted several ways, but I take this to mean revert the item back to the last "true" state, as defined by the external backend. Since the backend is blind to the omitted fields, I'd expect the omitted fields to be... omitted from the state.

In my specific use case, I'm using an omitted field to keep track of whether the user has selected an item. If the user makes a change to the item while it is selected, saves the change to the server, and deselects the item, the next time the user reverts a change, the item will be selected again.

@jmdobry
Copy link
Member

jmdobry commented Aug 27, 2015

This is a good point.
On Aug 26, 2015 10:39 PM, "Austin Whittier" notifications@github.com
wrote:

Just as the title says. The docs say:

Synchronously revert the state of an item to the last time it was saved
via an async adapter. Returns the reverted item.

I know it can be interpreted several ways, but I take this to mean revert
the item back to the last "true" state, as defined by the external backend.
Since the backend is blind to the omitted fields, I'd expect the omitted
fields to be... omitted from the state.

In my specific use case, I'm using an omitted field to keep track of
whether the user has selected an item. If the user makes a change to the
item while it is selected, saves the change to the server, and deselects
the item, the next time the user reverts a change, the item will be
selected again.


Reply to this email directly or view it on GitHub
#205.

@awhitty
Copy link
Author

awhitty commented Aug 27, 2015

I'm not too familiar with the js-data codebase, but I can try to draft up a pull-request in the next few days if you're interested in incorporating this?

I imagine something like

var item = Item.get(5);
item.DSRevert({
  skipOmittedFields: true
});

would be enough.

I asked about skipping over fields in the gitter channel for an unrelated use case where I have two forms responsible for editing different parts of an item in the store, and I'd like to be able to cancel changes from one form without reverting the changes in the other form. I understand that this use case is a bit more unique than the one that I've described above, but I imagine this would be a good opportunity to add functionality that would cover both cases.

In my mind something like

var item = Item.get(5);
item.DSRevert({
  skip: ['title', 'author']
});

would get us there, and the skipOmittedFields from above would just append the omitted fields array to this skip array.

@jmdobry
Copy link
Member

jmdobry commented Aug 27, 2015

Both of those suggestions sound good
On Aug 27, 2015 12:55 PM, "Austin Whittier" notifications@github.com
wrote:

I'm not too familiar with the js-data codebase, but I can try to draft up
a pull-request in the next few days if you're interested in incorporating
this?

I imagine something like

var item = Item.get(5);
item.DSRevert({
skipOmittedFields: true
});

would be enough.

I asked about skipping over fields in the gitter channel for an unrelated
use case where I have two forms responsible for editing different parts of
an item in the store, and I'd like to be able to cancel changes from one
form without reverting the changes in the other form. I understand that
this use case is a bit more unique than the one that I've described above,
but I imagine this would be a good opportunity to add functionality that
would cover both cases.

In my mind something like

var item = Item.get(5);
item.DSRevert({
skip: ['title', 'author']
});

would get us there, and the skipOmittedFields from above would just
append the omitted fields array to this skip array.


Reply to this email directly or view it on GitHub
#205 (comment).

@internalfx
Copy link
Member

I retract my argument.

Looks like this preserves existing functionality. 👍

@internalfx
Copy link
Member

@awhitty @jmdobry please see PR

@internalfx
Copy link
Member

Oh, I also used the term "preserve" I thought it best described what it did.

Comments?

@internalfx
Copy link
Member

item.DSRevert({
  preserve: ['title', 'author']
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants