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 973d83e
Show file tree
Hide file tree
Showing 2 changed files with 27 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
21 changes: 21 additions & 0 deletions test/unit/view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,25 @@ 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);
dv.removeTransform('filter');
expect(dv.transforms.length).to.equal(0);
});
});

0 comments on commit 973d83e

Please sign in to comment.