I have an existing application built on ExtJS. We have buttons across multiple views. We have a change request that, whenever a button was clicked, some function should be called before the actual logic fires. This function call is applicable for all button click events.
How can we handle this scenario in ExtJS?
1
votes
How are the handlers/listeners attached in your current case?
– A1rPun
In the controller, we added refs to every control and bind the method calls to the click listeners
– rajmalhotraml
Look at this solution.
– A1rPun
1 Answers
1
votes
What's stopping you from adding the function that's always called to each of the listeners.
click: function(btn) {
functionThatAlwaysRuns();
// rest of your button specific logic here
}
This sounds like code that you can clean up significantly by tying all the buttons to a common listener in a controller, and using the strategy pattern to determine which specific logic to run after the generic function though. A good example can be found here for the strategy pattern: http://encosia.com/first-class-functions-as-an-alternative-to-javascripts-switch-statement/