Answer the question
In order to leave comments, you need to log in
How to call change event handlers before and after?
So, there is an abstract data structure change event.
There are two handlers:
1. Called before the change. Complements it and validates it (may prevent this change).
2. Called after the change. Brings the surrounding world into a state consistent with this change.
So, we need to come up with names for them.
It is important to do this now, because then there will be thousands of implementations of these handlers in the code.
There are currently three pairs of candidates:
1. beforeChange and afterChange.
2. preChange and postChange.
3. validate and trigger.
For now, I'm leaning towards the second option. Here are the pros and cons I see:
1.
+ Simple and clear
- Because as parameters of both handlers, the states before and after the change will be passed, i.e. before and after, there will be confusion:
function beforeChange(before, after) {}
function afterChange(before, after) {}
Answer the question
In order to leave comments, you need to log in
that is, one handler processes the component itself, and the second handles other components, and "before" and "after" do not make any sense here at all, because the logic of these handlers belongs to different objects,
it is much more logical to hang the second handler on the component that should synchronize with the first one and attach a listener for the change event of the first component on it,
your option is called micromanagement, as if your boss told you every time how you should do your job
1) before and after are used in databases
2) In the state graph (programmable logic controllers), procedures are called enter (entry) and exit
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question