Skip to content

Commit f0bc017

Browse files
committed
Respond to PR comments.
1 parent 5912aaa commit f0bc017

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"main": "./lib/actions/write.js",
4343
"title": "Write CSV attachment",
4444
"fields": {
45-
"reader": {
45+
"writer": {
4646
"viewClass": "CSVReadView"
4747
}
4848
},

lib/actions/write.js

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ let rowCount = 0;
1515
exports.init = function init(cfg) {
1616
return co(function* gen() {
1717

18-
const delimiter = cfg.reader.delimiter || ',';
18+
const delimiter = cfg.writer.delimiter || ',';
1919
console.log('Using delimiter: \'%s\'', delimiter);
2020
const options = {
2121
header: true,
2222
delimiter
2323
};
2424

25-
if (cfg.reader.columns) {
25+
if (cfg.writer.columns) {
2626

27-
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
27+
const columns = Object.keys(_.keyBy(cfg.writer.columns, 'property'));
2828

2929
console.log('Configured column names:', columns);
3030
options.columns = columns;
@@ -44,11 +44,6 @@ exports.init = function init(cfg) {
4444
exports.process = function ProcessAction(msg, cfg) {
4545
// eslint-disable-next-line consistent-this
4646
const self = this;
47-
const startRow = cfg.reader.startRow || 0;
48-
49-
if (startRow !== 0 && rowCount === 0) {
50-
console.log('Skipping the first %s rows', startRow + 1);
51-
}
5247

5348
if (timeout) {
5449
clearTimeout(timeout);
@@ -57,7 +52,7 @@ exports.process = function ProcessAction(msg, cfg) {
5752
timeout = setTimeout(() => {
5853
console.log('Closing the stream due to inactivity');
5954
co(function* gen() {
60-
const finalRowCount = rowCount - startRow;
55+
const finalRowCount = rowCount;
6156
console.log('The resulting CSV file contains %s rows', finalRowCount);
6257
stringifier.end();
6358

@@ -79,48 +74,12 @@ exports.process = function ProcessAction(msg, cfg) {
7974
});
8075
}, 10000);
8176

82-
if (startRow <= rowCount) {
83-
let row = msg.body;
84-
if (cfg.reader.columns) {
85-
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
86-
row = _.pick(msg.body, columns);
87-
}
88-
stringifier.write(row);
77+
let row = msg.body;
78+
if (cfg.writer.columns) {
79+
const columns = Object.keys(_.keyBy(cfg.writer.columns, 'property'));
80+
row = _.pick(msg.body, columns);
8981
}
82+
stringifier.write(row);
9083
rowCount++;
9184
this.emit('end');
9285
};
93-
94-
/**
95-
96-
97-
co(function* proc() {
98-
yield init();
99-
100-
for (let i = 0; i <= 100; i++) {
101-
102-
processAction({
103-
body: {
104-
run: i,
105-
timestamp: Date.now()
106-
}
107-
});
108-
}
109-
110-
setTimeout(()=> {
111-
112-
console.log('Next round');
113-
114-
115-
for (let i = 100; i <= 200; i++) {
116-
117-
processAction({
118-
body: {
119-
run: i,
120-
timestamp: Date.now()
121-
}
122-
});
123-
}
124-
}, 10000);
125-
});
126-
**/

0 commit comments

Comments
 (0)