question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Clean up core APIs

See original GitHub issue

Change add* to register*

I had some really nice feedback tonight from some of the old folks who used to work at Meta on DraftJS. They mentioned that the current pattern of addListener, addTransform etc was confusing – as it’s assumed to be just “adding” something. They expected there to be an opposite API of removeListener and removeTransform.

They mentioned that we could do what other popular libraries do, and create an observe or use a register prefix, which infers that you’re creating something that has a return signature. This would mean the following changes:

  • addListener -> registerListener
  • addNodeTransform -> registerNodeTransform

This should hopefully make it clear that these APIs return the removal variants of themselves.

Let’s break out command listeners

They’re not really listeners, and never have been. Listeners don’t expect the function to return anything, but command listeners do – and they also have priorities! So let’s come up with a better naming for both the listening part and the dispatching part! My current thinking is:

  • addListener('command', function, priority) -> registerCommandHandler(function, priority)
  • execCommand(commandType, payload) -> dispatchCommand(commandType, payload)

Let’s remove root listeners

I really don’t feel they push folks down the path of success. They encourage adding listeners to the contenteditable, but really they should probably be delegating events to the document and, where possible, leveraging commands instead.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
trueadmcommented, Mar 22, 2022

I like Amy’s idea around the register prefix instead of create. What do others think?

2reactions
trueadmcommented, Mar 23, 2022

@thegreatercurve We should keep textcontent listeners, purely because it avoids the user from having to use update listeners too much (they fire much more frequently than textcontent listeners do).

We used to have explicit listeners, i.e. registerUpdateListener etc, the reason we moved away from them was to make it feel more web like. However, I’m not really seeing any real benefits from that right now, so you’re probably right!

Read more comments on GitHub >

github_iconTop Results From Across the Web

proposal-cleanup-some/README.md at master - GitHub
This method provided a way for library authors to synchronously allow them to clean up without yielding to the event loop. We propose...
Read more >
Proposal Core Unit Budget Streams, SPF Funding, HVBank ...
See the results of the MakerDAO executive proposal Core Unit Budget Streams, SPF Funding, HVBank Legal Update, MKR Stream Accounting Cleanup ...
Read more >
Proposal: Introduce method results memoization API in the ...
Abstract: I propose to introduce a simple core API for memoizing ... growth control (with too many argument-result pairs memoized), cache cleanup, etc....
Read more >
Ruby bindings for the Subversion client library: Proposal
Specifically, I will upgrade the Ruby binding API to support 15 new functions: blame, cleanup, ... 8 new Ruby API constants: * Svn::Core::INVALID_REVNUM, ......
Read more >
Request for Proposal Demolition and Property Cleanup for ...
23340 CREE ST. NW. ST FRANCIS, MN 55070. 763-235-2309. Request for Proposal. Demolition and Property Cleanup for. 23115 Ambassador Blvd NW.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found