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

Clean Up API, Break Backwards Compatibility #468

Closed
hipstersmoothie opened this issue Jul 22, 2018 · 5 comments
Closed

Clean Up API, Break Backwards Compatibility #468

hipstersmoothie opened this issue Jul 22, 2018 · 5 comments

Comments

@hipstersmoothie
Copy link
Collaborator

It seems like there is a lot of work being done to ensure that the package is backward compatible. This seems a little odd to me and has led to weird API decisions. Some methods are chain-able via this, some return promises, and some use a node style callback. I believe we should decide on a consistent way of doing things and bump to the version to 1.0.0 since we will probably be breaking some things along the way.

Another thing we should look at is how we pass arguments. Currently it can be variable and leads to many situation where we would have to make a major release(SemVer). Some other PRs and Issues discuss passing an options object instead. I think this would be the better way to go and would allow us to iterate quicker without breaking the API.

@hipstersmoothie
Copy link
Collaborator Author

@edi9999

@edi9999
Copy link
Contributor

edi9999 commented Jul 23, 2018

yes I agree with you.

The API should be coherent.

I think all methods returning something asynchronously should use Promises.

For option parameters, at least for boolean parameters, and probably for all, we should use an options object to set the parameters, makes sense.

@hipstersmoothie hipstersmoothie changed the title Clean Up API Clean Up API, Break Backwards Compatibility Jul 25, 2018
@hipstersmoothie
Copy link
Collaborator Author

hipstersmoothie commented Jul 25, 2018

I propose every function now takes a options object even if they only have 1 arg.

  • supports adding more options to any function in the future without breaking changes
  • when done will be a breaking change
  • simplifies the code a lot

We should also continue to support chaining as much as possible. So code like this should work.

Jimp.read('some-image.png')
	.resize(100, 100)
	.write('some-image-medium.png')
	.resize(25, 25)
	.write('some-image-small.png');

Functions that take node-style-callbacks that should return promises:

Take callback but don't need to (nothing async is done). So we can just remove the callback. They will either return a value or this depending on current implmentation:

  • Jimp.rgbaToInt
  • Jimp.intToRGBA
  • Jimp.prototype.deflateLevel
  • Jimp.prototype.deflateStrategy
  • Jimp.prototype.filterType
  • Jimp.prototype.rgba
  • Jimp.prototype.getPixelIndex
  • Jimp.prototype.getPixelColor
  • Jimp.prototype.setPixelColor
  • Jimp.prototype.hash
  • Jimp.prototype.blit
  • Jimp.prototype.mask
  • Jimp.prototype.composite
  • Jimp.prototype.brightness
  • Jimp.prototype.contrast
  • Jimp.prototype.posterize
  • Jimp.prototype.flip
  • Jimp.prototype.gaussian
  • Jimp.prototype.blur
  • Jimp.prototype.convolution
  • Jimp.prototype.opacity
  • Jimp.prototype.fade
  • Jimp.prototype.resize
  • Jimp.prototype.cover
  • Jimp.prototype.contain
  • Jimp.prototype.scale
  • Jimp.prototype.scaleToFit
  • Jimp.prototype.pixelate
  • Jimp.prototype.convolute
  • Jimp.prototype.rotate
  • Jimp.prototype.displace
  • Jimp.prototype.color
  • Jimp.prototype.print
  • Jimp.prototype.getBuffer (used to have async stuff but now is totally sync) Promise based write/getBuffer #90 write, getBuffer, getBase64 can be Promised #374
  • Jimp.prototype.getBase64 (see above, can be sync now) write, getBuffer, getBase64 can be Promised #374

Related Issues to be closed:

@hipstersmoothie
Copy link
Collaborator Author

@edi9999 thoughts?

@hipstersmoothie
Copy link
Collaborator Author

Should every method just return a promise? might make the desired syntax hard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants