Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(view): Support to remove transform #59

Closed
wants to merge 1 commit into from
Closed
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
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeTransform 和 executeTransform 的职能区分开?

}
_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' }
]);
});
});