electron-clipboard-watcher
electron-clipboard-watcher copied to clipboard
API notes/ideas
Hey! I mentioned that I felt the electron-clipboard-watcher API "wasn't ideal" in a commit to phuedx/copypasta. Firstly, it's worth noting that I don't use every feature of the API so my idea of ideal likely isn't yours. Well then…
Distinguish Required And Optional Parameters
The following runs without error:
const clipboardWatcher = require('electron-clipboard-watcher')
clipboardWatcher() // or clipboardWatcher({ watchDelay: 100 })
As a client, I expect and observe that watchDelay is optional; onImageChange or onTextChange should be required, though. The easiest way to achieve this would be to throw if neither of them was present.
Consider Extending 🦄 💥 EventEmitter 💥 🦄
If the handlers truly are optional, then perhaps a more Node-like API would be as follows:
const clipboardWatcher = require('electron-clipboard-watcher')
clipboardWatcher(100) // watchDelay
.on('text', text => { /* ... */ })
.on('image', image => { /* ... */ })
Note that this is a little more flexible than the current API as multiple handlers can handle an event.
I'll follow up with a comment about Observable. Who doesn't ❤️ Observable?