Skip to content

Commit

Permalink
feat(view): Support to remove transform, close #53
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Jul 1, 2019
1 parent 55526ac commit 6d316f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ class View extends EventEmitter {
me._executeTransform(options);
return me;
}
removeTransform(type) {
const me = this;
me.transforms = me.transforms.filter(item => item.type !== type);
me._reExecute();
return me;
}
_executeTransform(options) {
const me = this;
options = me._preparseOptions(options);
Expand Down
34 changes: 34 additions & 0 deletions test/unit/view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,38 @@ describe('View', () => {
});
dv.source(populationChina);
});

it('removeTransform', () => {
const dv = new View();
const data =
`Expt,Run,Speed
1,1,850
1,2,740
1,3,900
1,4,1070`;
dv.source(data, {
type: 'csv'
}).transform({
type: 'filter',
callback(row) {
return row.Run !== '1';
}
});
expect(dv.transforms.length).to.equal(1);
// eslint-disable-next-line
expect(dv.rows).to.eql([
{ Expt: '1', Run: '2', Speed: '740' },
{ Expt: '1', Run: '3', Speed: '900' },
{ Expt: '1', Run: '4', Speed: '1070' }
]);
dv.removeTransform('filter'); // remove filter transform
expect(dv.transforms.length).to.equal(0);
// eslint-disable-next-line
expect(dv.rows).to.eql([
{ Expt: '1', Run: '1', Speed: '850' },
{ Expt: '1', Run: '2', Speed: '740' },
{ Expt: '1', Run: '3', Speed: '900' },
{ Expt: '1', Run: '4', Speed: '1070' }
]);
});
});

0 comments on commit 6d316f4

Please sign in to comment.