Q
Q
Q2W2017-12-09 00:08:06
Programming
Q2W, 2017-12-09 00:08:06

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) {}

- Names are not verbs.
2.
+ Almost as simple and clear.
- Names are not verbs.
3.
+ validate - verb.
+ Most often, validate will contain validation.
+ trigger is a very accurate name.
- in validate there is not only validation, its meaning is somewhat wider (I described above).
- trigger is not a verb.
- some non-obvious names, it seems.
What do you think? Maybe there are some well-established names in this regard?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
oh, 2017-12-09
well @AnneSmith

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

A
Alexander Skusnov, 2017-12-09
@AlexSku

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 question

Ask a Question

731 491 924 answers to any question