-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
load multiple models in an infinity route #67
Comments
Yup! You just wanna set the
|
Thanks a ton! Worked like a charm, just had to use, |
RIGHT yeah i missed the setup controller call NICE |
export default Ember.Route.extend(InfinityRoute, {
model(){
return {
sellableProducts: this.infinityModel('product', {product_type: 1, perPage: 30, startingPage: 1, modelPath: 'controller.model.sellableProducts'}),
adsProducts: this.infinityModel('product', {product_type: 0, perPage: 30, startingPage: 1,modelPath: 'controller.model.adsProducts'}),
trendingProducts: this.store.query('product', {trending: true, product_type: 1})
};
},
updateInfinityModel(newObjects){
let infinityModel = this.get(this.get('_modelPath')).get('content');
let content = newObjects.get('content');
infinityModel.pushObjects(content);
}
}); How to load two different infinity model on same page? |
You would need to wrap your model in a import Ember from 'ember';
import InfinityRoute from "ember-infinity/mixins/route";
export default Ember.Route.extend(InfinityRoute, {
model(params) {
return Ember.RSVP.hash({
trendingProducts: this.store.query('product', {trending: true, product_type: 1}),
sellableProducts: this.infinityModel('product', {
perPage: 30,
startingPage: 1,
product_type: 0,
// ---> THE MAGIC
modelPath: 'controller.sellableProducts'
})
});
},
setupController(controller, model) {
controller.setProperties(model);
}
}); |
thanks @mockra - however I believe he wants two different infinityModels, which we don't currently support on the same route |
Ah you're right. Sorry, just woke up :D. |
good morning @mockra !! |
Thanks a lot! Do you think it could be useful to add this use case in the readme? |
@hhff So, the expected behavior is, aaa has an infinity model and should work and its child route has infinity model which should work. BUT IT DOES NOT. Is this in a way same as having 2 infinity active on the same page? Can you help my understanding here??? |
HI @venkz - that should work fine provided both routes are setup properly. The reason we can't have two infinityModels on the same route is related to the |
@hhff |
Ahh! Yeah - you'll need to specify the |
@hhff Looking at your mixin implementation, you haven't specified any property as computed. What this means from the understanding I have is that, a common instance of mixin is shared between all implementing routes. So if my route 'aaa' implemented this first, model is set to 'model-a' and later as the child route is rendered, the mixin's context is changed and since there is no computed alias for each property, they are changed to hold 'model-b' |
I'm not sure I'm following, I'm sorry. If you can put up a repo to reproduce the issue, I'll take a look. |
I did some debugging having break points. This is what I ended up with. The scrollable on component is working fine and triggers the this.sendAction('loadMoreAction'); Once the call on route is invoked, it calls The modelName here is always 'model-b'. So, it is pushing new records to model-b instead of model-a Can you visualize the usecase here? @hhff |
Irrespective which scrollable is triggering the event this.sendAction('loadMoreAction'); your route will always request for this.get('_infinityModelName'); which is pointing to the last route that implemented your mixin. (in my case model-b) |
Hi @venkz ! I'm sorry I still can't visualize this. A demo would be the most useful way to get to the bottom of it. |
Here you go... https://github.com/venkz/ember-multi-infinity-scroll I have set it up to use mirage data. There are 2 scrolls on the same page each rendered from different routes. Same as the problem I explained before. |
hi @venkz - confirmed this bug. This one is surprising to me: In ember - when a controller bubbles an action, it will bubble it to the deepest route of the current router state. I had always assumed the You can see this in action if you create a simple button on the I'm going to sleep on this and get back to you! hx |
@hhff Yea, that is true. It is always sending the action to child route when we expect it to send it to parent route!!! This seems to be a bug or "unexpectedly expected" behavior of Ember.... How do you plan to tackle this?? |
@venkz - please check my PR here: venkz/ember-multi-infinity-scroll#1 That should solve your problem for now. (most of the changed files are from using Setup an issue to figure out a "nicer" API for this issue. Thanks for reporting + u can follow along here: |
I'm using So I try to follow the solution with
But this doesn't work, when I use |
Hi @danilovaz - this has nothing to do with the existing issue. Can you please open a new one? I'd like for Ember Infinity to work for your use case. |
@hhff Sure, I'll do this. Thanks! |
Is there anyway to support an InfinityModel if it's not the only model being loaded through the route. Here's an example of what I'd like to do:
Thanks!
The text was updated successfully, but these errors were encountered: