You need to sign in to do that
Don't have an account?
suneel.patchipulusu@gmail.com
Explanation of code!!!!!!!!
Hello all
Could any one explain this part of code, I am unable to understand
// Internal mapping of handlers Map<String, List<Handler>> eventHandlerMapping = new Map<String, List<Handler>>(); /** * Core API to bind handlers with events */ public Triggers bind(Evt event, Handler eh) { List<Handler> handlers = eventHandlerMapping.get(event.name()); if (handlers == null) { handlers = new List<Handler>(); eventHandlerMapping.put(event.name(), handlers); } handlers.add(eh); return this; }
The above code belongs to the standard trigger template
Thanks in advance
Suneel
For each event, create a list of handlers, then add the event and list of handlers to a map of events to their handler lists.
Hi
Thanks for ur response and I have a small doubt
What does it mean
Is it a constructor with arguments or??
Triggers, Evt, and Handler are all classes. This function is not a constructor, just a normal function that adds a handler to an event key, creating the list if it doesn't exist first. It then returns a reference to itself, which allows function chaining:
By the way, this function could have been written as:
Which might seem more intuitive for you to read.