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

Provides data object to repeater render callbacks #1869

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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