Skip to content

Eject before HTTP destroy #169

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

Closed
elado opened this issue Sep 13, 2014 · 5 comments
Closed

Eject before HTTP destroy #169

elado opened this issue Sep 13, 2014 · 5 comments
Assignees
Milestone

Comments

@elado
Copy link

elado commented Sep 13, 2014

Right now, when destroying an item, eject is called only after the HTTP is resolved.

In the UI, it'll update the list only after it was ejected. For a more responsive UI, eject can (optionally?) happen before destroy, same for create+inject.

@jmdobry
Copy link
Member

jmdobry commented Sep 13, 2014

I could work something out for eject and ejectAll, but for create the item doesn't have a primary key yet, so it can't be injected until it has one.

@elado
Copy link
Author

elado commented Sep 13, 2014

In many cases the UI doesn't need to wait until the HTTP is done. Cases like <type> <enter> <type> <enter> <type> <enter> are common.

My suggestion is to manage a list of pending items:

Before create, mark the item as pending, inject without ID (or with a generated random ID).
After a successful HTTP request set the ID from the server, remove the pending flag.
After an error, mark as errored.

It brings more ideas that would help offline data, request queues and retries, but that's another subject.

@jmdobry
Copy link
Member

jmdobry commented Sep 13, 2014

Have your tried either of these?

// inject and eject emit events on $rootScope, can be configured to $emit, $broadcast, or none
$rootScope.$on('DS.eject', function ($event, resourceName, ejectedItem) {
  // ...
});

Or

// Emit events yourself
DS.defineResource({
  name: 'category',
  afterDestroy: function (resourceName, attrs, cb) {
    $rootScope.$broadcast('destroy', resourceName, attrs);
    cb(null, attrs);
  }
});

Edit: I meant to post this on #170

@elado elado mentioned this issue Sep 13, 2014
@elado
Copy link
Author

elado commented Sep 14, 2014

Here's a POC for inject before create and eject before destroy: elado@a84c5c3

Tests are broken but this is just a start.
The intention is to inject a pending item (which also calls beforeInject/afterInject) and when HTTP request is done it's ejecting the pending item (without calling DS.eject) and injecting the new item (without calling before/afterInject).

Tested on my UI and it's way more responsive. It doesn't wait for the endpoint to response, so "type, enter, type, enter, type, enter" just works without delays.

Thoughs?

@jmdobry jmdobry added this to the 1.0.0-rc.2 milestone Sep 21, 2014
@jmdobry jmdobry self-assigned this Sep 21, 2014
@jmdobry jmdobry added done and removed in progress labels Sep 21, 2014
@elado
Copy link
Author

elado commented Sep 22, 2014

Awesome!!! Thanks.

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

2 participants