By convention, the name of the event handler as an attribute of a component should comply with that of an HTML tag, e.g. onTextChange, following the pattern onSubjectEvent, while the specific function that acts as the event handler should have a name with the pattern handleSubjectEvent. Here the "Event" is just the simple form (e.g. Change) of a verb, not a past participle (Changed) or a present participle (Changing).
This convention is easy to follow when the subject has a short name. However, there are many occasions when the subject name is long due to a long modifier as we would like to make the name as self-explained as possible.
E.g., complying with the HTML convention, onNameAdd and handleNameAdd look fine,
but onOverseasSuppliersLegalNameAdd and handleOverseasSuppliersLegalNameAdd look unbalanced.
I've seen some developers who are native English speakers name the handler as onAddOverseasSuppliersLegalName, following a onEventSubject pattern. And some of them even stick to this pattern when the subject name is short, like onAddName, which contradicts the HTML convention.
I have searched for this issue, but people are only talking about the case of a short subject name, so I was wondering how you would name an event handler when the subject name is short and long, respectively.
Strictly follow the HTML convention.
E.g. onNameAdd & onOverseasSuppliersLegalNameAdd
Put the event name (or the verb) between on/handle and the subject to avoid an unbalanced handler name when the subject name is long.
E.g. onAddName & onAddOverseasSuppliersLegalName
It depends on the length of the subject name. When it's short, follow the HTML convention; when it's long, put the verb in the middle.
E.g. onNameAdd & onAddOverseasSuppliersLegalName