Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1869 from cormacmccarthy/GH1867---paging-is-not-w…
Browse files Browse the repository at this point in the history
…orking-as-it-did-previously-for-repeater-with-infinite-scroll

Provides data object to repeater render callbacks
  • Loading branch information
chriscorwin authored Sep 22, 2016
2 parents cb0bfed + 6894504 commit 7b15b88
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@
this.$loader.hide().loader('pause');
this.enable();

this.$search.trigger('rendered.fu.repeater');
this.$search.trigger('rendered.fu.repeater', {
data: data,
options: state.dataOptions,
renderOptions: state.options
});
this.$element.trigger('rendered.fu.repeater', {
data: data,
options: state.dataOptions,
Expand Down Expand Up @@ -786,7 +790,7 @@
addItem(this.$canvas, addAfter);
}

callback();
callback(data);
} else {
viewTypeObj.render.call(this, {
container: this.$canvas,
Expand Down
45 changes: 45 additions & 0 deletions test/repeater-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,51 @@ define(function repeaterTests (require) {
$repeater.repeater();
});

asyncTest('rendered.fu.repeater callback should receive correct data when called by renderItems function', function dataSourceCallbackTest () {
var $repeater = $(this.$markup);
var count = 0;
$repeater.on('rendered.fu.repeater', function(e, state) {
count++;
if (count === 2) {
start();
}

ok(state.data, 'data object exists');
equal(state.data.myVar, 'passalong', 'data returned from datasource was passed along');
});
$repeater.repeater({
views: {
'test1.view1': {
dataSource: function dataSource (options, callback) {
callback({myVar: 'passalong'});
}
}
}
});
});

asyncTest('custom view\'s render function should receive correct data when called by renderItems function', function dataSourceCallbackTest () {
var $repeater = $(this.$markup);

$.fn.repeater.viewTypes.test1 = {
render: function(state, callback) {
start();
ok(state.data, 'data was passed to custom viewtype callback');
equal(state.data.myVar, 'passalong', 'data returned from datasource was passed along to custom viewtype callback');
callback(state.data);
}
};
$repeater.repeater({
views: {
'test1.view1': {
dataSource: function dataSource (options, callback) {
callback({myVar: 'passalong'});
}
}
}
});
});

asyncTest('should destroy control', function destroy () {
var $repeater = $(this.$markup);

Expand Down

0 comments on commit 7b15b88

Please sign in to comment.