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

$promise and $httpPromise not always defined on cached objects inside an Array #66

Open
makebbekus opened this issue Jan 28, 2015 · 0 comments
Labels

Comments

@makebbekus
Copy link
Contributor

Currently, when you read a single value from the cache, $promise and $httpPromise are set on the object:

    instance = new CachedResource
      $promise:     cacheDeferred.promise
      $httpPromise: httpDeferred.promise

However, when you read an array value from the cache, it's more complicated, and currently $promise and $httpPromise are only set on the Array and not the objects in the array.

@serhalp and I took a pass at fixing this, but it's pretty nuanced. Here's our current thinking about read_array_cache.coffee:

Currently the order is:

  1. Flush writes
  2. Kick off an async HTTP request and sometime later resolve the array $promise and $httpPromise
  3. If we have local data, load it from the cache and resolve the array $promise

Because of the async nature of the HTTP request, there are a couple states where we'd need to manage promises on the individual objects in the arrays:

  1. We have local data so the Array $promise is resolved, but we're waiting on the array $httpPromise, so we want the objects in the array to have their own $promise resolved with the cached object and an $httpPromise that is not resolved
  2. When the HTTP data comes back from the server the Array $promise and $httpPromise are resolved, so we want the objects in the array to have $promise resolved (either it was already resolved with local data in step 3 or if there was no local data it now gets resolved with fresh data) and $httpPromise resolved with the modified data (server + local via modifyObjectInPlace)
@makebbekus makebbekus added the bug label Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant