konvajs / konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://konvajs.org/
Other
11.46k stars 920 forks source link

[Proposal] Change API of Filters #380

Closed lavrton closed 3 years ago

lavrton commented 6 years ago

Currently, I don't really like our API of filters. Each filter adds its own special properties to every Konva.Node instance. For example Konva.Filters.RGB will add three new methods: red(), green(), blue() (also it will add get and set prefixed methods). As we have many filters, all of them adds tons of new methods to the prototype. Documentations become messed with some many methods. Also, too many methods in prototype may make it slower. And such code is not very modular.

So your current API is:

node.cache();
node.filters([Konva.Filters.RGB]);
node.red(100);

How can we make it better?

What about this:

node.cache();
var rgbFilter = new Konva.Filters.RGB();
rgbFilter.red(100);
node.filters([rgbFilter]);
lavrton commented 5 years ago

Another suggestion:

node.cache();
node.filters([createRGBFilter({ red: 100})])
lavrton commented 3 years ago

Closing as not a priority.