So there is a change event abstract data structures.
There are two handlers:
1. Called before the change. Complements and validates it (can prevent this change).
2. Called after the change. Leads the world in consistent with this change in status.
So, you have to come up with names.
It is important to do it now, because then in the code there are thousands of implementations of these handlers.
At the moment there are three pairs of candidates:
1. beforeChange and afterChange.
2. preChange and postChange.
3. validate and trigger.
While leaning toward the latter. Here are some pros and cons I see:
1.
+ Simple and clear
In as parameters both processors will be transferred to the state before the change and after, ie before and after, there will be confusion:
function beforeChange(before, after) {}
function afterChange(before, after) {}
- Names are not verbs.
2.
+ Almost as simple and clear.
- Names are not verbs.
3.
+ validate - verb.
+ Most often it will validate validation.
+ trigger a very accurate name.
in the validate is not only validation, its meaning is somewhat broader (I described above).
- trigger not a verb.
- some not so obvious titles like.
What do you say? Maybe there are some established names on this?
No, the handler "to" can check something in the external world (e.g., objects from our data structures).
Obrabotki differ from each other only in two things:
1. One is called before applying the changes to the data structure, and the other after.
2. The first can prevent the change and the other doesn't. - baron_Quigl commented on June 10th 19 at 17:04
there are no handlers to events, there are handlers that run on event - load, click, change, etc.
if you think that you have a handler "before the event", you simply ignore the actual event that this handler is run
you can't light a lamp before it hit the light switch, so there must be an event trigger, even if you don't want to see.
again, the handler of the ban on the change of the structure must belong to the object structure, and listen to your first event object, the value of which determines the possibility of changes in the structure: roughly speaking, the flag - if 1, then the light can be switched on and 0 to off
you do not have a clear and integral structure of the application you're working on, so you have to resolve the chaos of the supposedly different handlers, when in fact all engines are the same - Pedro65 commented on June 10th 19 at 17:07