View Full Version : Promise-based event model?

15 Dec 2011, 9:14 AM

To reduce components coupling into my applications (ExtJS 3.x) , my components are only fireing events which are handled afterwards by the application or other components. This works well, but sometime, the component that have fired an event would like to be notified on how the event he fired was handled.

For example, a SearchBar component could fire a search. The application would catch this event and perform a search. Now let's say the search failed because the search query syntax was wrong. We would then want to mark the SearchBar's input invalid.

I have tought of 3 ways of solving this problem:

- Use a global message/event bus. The message bus instance would have to be injected in each components that is using it to avoid coupling. Now with the example, the component could now listen to the searchfinished topic on the message bus (that would have been posted by the application) and could retrive the result and mark itself invalid.

- Provide a public markInvalid method on the SearchBar component that would then be called after by the application.

- Implement a new event model based on the Promise pattern. That would allow doing something like:


The Promise pattern seems to be the future of asynchronous programming and I think all ExtJS developers would greatly benefit from a new Promise-based event model.

I would like to know how others would solve this problem and what they think about having a new event model based on the Promise pattern for ExtJS?

15 Dec 2011, 1:13 PM
Please post in the appropriate forum. I have moved this to the Ext JS 3 help forum.