Comments (14)
Rationale is I want to be able to determine whether there are genuinely no instances of a model on the server vs just there not being any instances on the client yet.
from data.
Just to be clear on semantics, what you're saying is that as soon as a single item for a type was added to the store, all findAll
queries for that type should switch to isLoaded
?
from data.
@wycats I'm okay with that, but the problem then is what happens if the server has no instances of that type?
My goal is to display a UI that says "There are no Cars", but I don't want to show this UI while any potential Cars are loading from the initial call to DS.Adapter#findAll
.
from data.
My 2 cents...
I also need some notification mecanism to perform some processing once the findAll has complete results loading.
Such a property would be observable, so processing could be triggered.
I may be wrong, but it seems to me this observation is quite "transient", and it is certainly useless to keep this observation after it has been triggered once.
In this case, what about a more simple "callback" mecanism, that would allow to perform processing once, after all (possible) data from server have been loaded?
@pixelcort Do my need meets yours?
@wycats Would it be ember-idiomatic to have such a callback mecanism?
from data.
Just found a solution to my problem, which could also match your need, @pixelcort : http://stackoverflow.com/a/9568939/90741
from data.
@MikeAndrzejewski that works but feels like Store#findQuery is a private method and that we should instead be using Store#find. Your workaround would probably also work with Store#filter with a function that always returns true, and that would guard against implementation detail changes inside of how findQuery works.
However, in any case, this doesn't resolve the issue, which is how do I determine whether the adapter returned no items for a given findAll query, or simply that it hasn't returned yet.
from data.
Updated title to better reflect issue.
from data.
Triggering a event once the ModelArray
starts populating and once it has finished populating would cover my usecase perfectly.
from data.
+1 this is pretty annoying...
from data.
Here's how I worked around this issue.
I created a new DS.Adapter
and implemented findAll
such that its success callback sets an isLoaded
property to true
on the DS.RecordArray
that is returned and cached in the store.
findAll(store, type) {
var request = { ... }
var success = function(data, status, xhr) {
data = JSON.parse(data);
store.loadMany(type, data);
store.typeMapFor(type).findAllCache.set('isLoaded', true);
}
$.ajax({
'url': 'data.php',
'type': 'POST',
'data': {request: JSON.stringify(request)},
'success': [success],
'async': async
});
}
Seems to be working for me. I can now observe isLoaded
on a findAll
's return value.
from data.
@mmpestorich nice workaround; I'll try using that next time. Thanks!
from data.
I just posted Pull Request #271 that implements isLoaded
on DS.RecordArray
. With these changes, the resulting array from store.findAll
and store.findMany
can be used in similar fashion to that of store.findQuery
. I've tested it every which way I can think of and it seems to do what I expect of it.
from data.
Looks like f707b6c addresses this.
from data.
It does. Thanks.
from data.
Related Issues (20)
- is there a design flaw in request lifetimes? HOT 9
- design issue: fetch handler doesn't provide response on error HOT 3
- bug: typescript error when using computed properties in conditionals HOT 1
- bug: async-to-async relationships may error when using `unloadAll` on both types HOT 12
- Preloading polymorphic relationship breaks on ember-data 5.3 HOT 2
- Feat - Additional Functionality Support in RequestManager for handler for Dynamic Handling beyond 'request' HOT 3
- Broken link in JSON Api ReadMe HOT 1
- cache.rollbackRelationships does not rollback the 2nd time after adding a record and rollback again HOT 3
- Understanding polymorphism HOT 2
- Assertion after saving a new relational record and tried to forget it HOT 4
- [3.28->4.7] `isLoaded` does not recompute if checked before the record has loaded. HOT 6
- Error `Could not find module `@warp-drive/core-types/request` imported from `(require)`` after update to 5.3.1 HOT 15
- ember-data date transform: triggering change on record re-insertion HOT 6
- bug: not tracking changes to empty relationship in 5.3.1+
- Breaks yarn install on Windows HOT 4
- Build broken after update from `5.3.0` to `5.3.3` HOT 3
- Deprecations will fire spuriously under strict ES module builds HOT 4
- Attributes with defaultValue functions not persisting HOT 8
- 🛤️ tracking: The Road to Polaris ✨ HOT 3
- Request can't handle `null` as response HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data.