Browse Source

Return unique row as data on step function (#500)

pull/581/head
Sergi Almacellas Abellana 6 years ago committed by GitHub
parent
commit
a7eb6343be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      papaparse.js
  2. 8
      tests/test-cases.js

7
papaparse.js

@ -1649,10 +1649,11 @@ if (!Array.isArray)
} }
/** Returns an object with the results, errors, and meta. */ /** Returns an object with the results, errors, and meta. */
function returnable(stopped) function returnable(stopped, step)
{ {
var isStep = step || false;
return { return {
data: data, data: isStep ? data[0] : data,
errors: errors, errors: errors,
meta: { meta: {
delimiter: delim, delimiter: delim,
@ -1667,7 +1668,7 @@ if (!Array.isArray)
/** Executes the user's step function and resets data & errors. */ /** Executes the user's step function and resets data & errors. */
function doStep() function doStep()
{ {
step(returnable()); step(returnable(undefined, true));
data = []; data = [];
errors = []; errors = [];
} }

8
tests/test-cases.js

@ -1735,7 +1735,7 @@ var CUSTOM_TESTS = [
run: function(callback) { run: function(callback) {
Papa.parse('A,b,c', { Papa.parse('A,b,c', {
step: function(response) { step: function(response) {
callback(response.data[0]); callback(response.data);
} }
}); });
} }
@ -1972,7 +1972,7 @@ var CUSTOM_TESTS = [
var updates = []; var updates = [];
Papa.parse('A,b,c\nd,E,f\nG,h,i', { Papa.parse('A,b,c\nd,E,f\nG,h,i', {
step: function(response, handle) { step: function(response, handle) {
updates.push(response.data[0]); updates.push(response.data);
handle.abort(); handle.abort();
callback(updates); callback(updates);
}, },
@ -2002,7 +2002,7 @@ var CUSTOM_TESTS = [
var updates = []; var updates = [];
Papa.parse('A,b,c\nd,E,f\nG,h,i', { Papa.parse('A,b,c\nd,E,f\nG,h,i', {
step: function(response, handle) { step: function(response, handle) {
updates.push(response.data[0]); updates.push(response.data);
handle.pause(); handle.pause();
callback(updates); callback(updates);
}, },
@ -2021,7 +2021,7 @@ var CUSTOM_TESTS = [
var first = true; var first = true;
Papa.parse('A,b,c\nd,E,f\nG,h,i', { Papa.parse('A,b,c\nd,E,f\nG,h,i', {
step: function(response, h) { step: function(response, h) {
updates.push(response.data[0]); updates.push(response.data);
if (!first) return; if (!first) return;
handle = h; handle = h;
handle.pause(); handle.pause();

Loading…
Cancel
Save