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

[FEAT BUGFIX] enable canonical state updates to deleted records #5408

Merged
merged 4 commits into from Apr 4, 2018

Conversation

runspired
Copy link
Contributor

@runspired runspired commented Apr 2, 2018

resolves #4995
replaces #5231

Problem

Records in the root.deleted.saved state currently error if new data is received from the server for the record while the record is still in the store.

For instance, a user may desire the following flow, which is now possible with this PR:

=> signal deletion (send actual `DELETE` request)
=> update ui state to isDeleting
=> receive notice of actual deletion
=> update ui state to isDeleted
=> unload

Use Case

Sometimes deletions are "soft deletes", and sometimes deletions may be queued on the server and the deleted state not reflect immediately in other requests.

2.13 Regression

Prior to 2.13 we would unload records whose deletion had been persisted. While this enabled folks to push server updates back into the store for either use case above, this would create a new record in the root.loaded.saved state, which is also unexpected.

This Fix

This fix enables canonical (but not dirty) state updates to root.deleted.saved records to still occur. Records are still available to the UI until the user opts to call unloadRecord. This means that end users may themselves decide whether they want to unload and treat these records as undeleted again, or maintain the deleted state.

Soft Delete

User's desiring soft delete aka archiving with the ability to resurrect a model should not be using deleteRecord or destroyRecord. While this PR will make soft-deletions via this mechanism work slightly better up until the point that resurrection is desired, users should instead fire an action to update a flag of their own making, and only fire a DELETE for a permanent deletion.

Copy link
Member

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM sans the try/catch within the test's run

}
})
} catch (e) {
assert.ok(false, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this try/catch achieve?

set(record, 'isArchived', true);
assert.ok(false, 'Was unable to dirty a deleted record');
} catch (e) {
assert.ok(true, e.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's assert the specific error rather than merely that there was an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

}
});
} catch (e) {
assert.ok(false, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this try/catch achieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can use expectAssertion here instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjdivad oh wait, actually, I can't unless there's a corollary? I basically want a "expect no assertion"

Copy link
Member

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@runspired runspired merged commit 3ed670d into emberjs:master Apr 4, 2018
@runspired runspired deleted the fix-push-on-deleted branch April 4, 2018 19:49
runspired pushed a commit that referenced this pull request Aug 29, 2018
* FIX push on deleted

* Add additional test coverage

* rm ghost file

* cleanup tests

* [CHORE] remove all usage of Ember.copy

fix package.json

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

Successfully merging this pull request may close these issues.

destroyRecord regression in 2.13.x
3 participants