jakubfiala / atrament

A small JS library for beautiful drawing and handwriting on the HTML Canvas.
http://fiala.space/atrament/demo
MIT License
1.55k stars 116 forks source link

Accept options object in constructor #32

Closed raphinesse closed 5 years ago

raphinesse commented 7 years ago

I guess it would be far more useful to have a signature like this

atrament(canvas, options)

where the second parameter is an object with properties corresponding to the publicly available properties on Atrament instances (according to the docs, that would include weight, color, smoothing, adaptiveStroke, mode and opacity) plus width and height (Even if I'd argue that you don't really need these last two. They're easily enough configured through the canvas element itself).

jakubfiala commented 7 years ago

@raphinesse thanks for the suggestion! I agree completely that such a signature would work better. It is an API-breaking change, so I'm going to flag this for v0.3.0.

Please do submit PRs if you can.

jakubfiala commented 7 years ago

stupid me, I meant to say v1.0.0

raphinesse commented 7 years ago

It doesn't have to be breaking. You could still support the old API and deprecate it. Something along the lines of:

function atrament(canvas, options) {
  if (typeof options === 'number') {
    console.warn('Calling style deprecated. Use new style instead. [Further information]')
    // convert old style arguments to options object
  }
  // Use new options object
}

To be more concise: overload the function :relaxed: