I am using the awesome plugin infinity-loader. It works great, providing I use it on the template of the route it is bound to.
But like a lot of people, now I decided to try and use it on a component. Oh dear. I understand how to bubble/send actions like this fiddle shows and this question explains.
Sadly this, this and this did not help.
What is strange is that after the first page, the Infinity add-on fires the action infinityLoad - if I remove my handler in my component, then I see the error 'nothing handled' the action in the console, so I know that the action is firing when I scroll to the end of the list.
But when my component 'bubbles it up' it just seems to get swallowed in the route and does not cause the add-on to fire its own internal handler.
/templates/employees/index.hbs
{{employees-list employeeModel=model sendThisAction='infinityLoad'}}
/routes/employees/index.js
import Ember from 'ember';
import InfinityRoute from "ember-infinity/mixins/route";
export default Ember.Route.extend(InfinityRoute, {
totalPagesParam: "meta.total",
model() {
return this.infinityModel("employee", { perPage: 10, startingPage: 1 });
},
// is this really needed, because my understanding is this action is automatically handled by the addon?
actions: {
infinityLoad() {
this.get('infinityModel').loadMore();
}
}
});
/templates/components/employee.hbs
<div class="list-group">
{{#each employeeModel as |employee|}}
<...display some employee stuff ...>
{{/each}}
</div>
{{infinity-loader infinityModel=employeeModel}}
/components/employee-list.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
infinityLoad() {
this.sendAction('sendThisAction');
}
}
});
NOTE I also tried solving this problem using this great add-on from Dockyard for sending actions to routes. The add-on works, but not my code.
UPDATE
With the code below the event now bubbles up and when I scroll the page I get the alert. But now I need to figure out how to get the loader (which is basically the grandchild of the route) to load the next page.
/templates/employees/index.hbs
{{employees-list employeeModel=model infinityLoad='infinityLoad'}}
/routes/employees/index.js
import Ember from 'ember';
import InfinityRoute from "ember-infinity/mixins/route";
export default Ember.Route.extend(InfinityRoute, {
totalPagesParam: "meta.total",
model() {
return this.infinityModel("employee", { perPage: 10, startingPage: 1 });
},
// is this really needed, because my understanding is this action is automatically handled by the addon?
actions: {
infinityLoad() {
alert('here we are'); <- test
}
}
});
/templates/components/employee.hbs
<div class="list-group">
{{#each employeeModel as |employee|}}
<...display some employee stuff ...>
{{/each}}
</div>
{{infinity-loader infinityModel=employeeModel}}
/components/employee-list.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
infinityLoad() {
this.sendAction('infinityLoad');
}
}
});
This helped figure that part out.