Unlocking the Power of Custom Events in Ext JS

I've been exploring the concept of custom events and trying to wrap my head around it. My goal is to have certain entities act as listeners and be able to trigger an event without needing to know who is listening.

In the main controller, I have an afterrender handler. I've confirmed that this handler is being called and a tab control is set up to listen for the userTimeOut event:

// Register components
registerComponent: function (component) {
    console.log('Registering ID: ' + component['id']);
    if (component['id'].indexOf('tab-') > -1) {
        console.log("Tab getting user timeout event handler: " + component['id']);
        component.on('userTimeOut', this.onUserTimeOut);
    }
    return true;
},

This is the onUserTimeOut handler:

onUserTimeOut: function (caller) {
    console.log('User timeout triggered\tID: ' + this['id'] + '\tCaller ID: ' + caller['id']);
}

In the main controller, there's code that is executed on a button click. I've verified that this code also gets executed:

fireUserTimeOut: function(button) {
    console.log('Firing User Time Out\tButton ID: ' + button['id']);
    Ext.GlobalEvents.fireEvent('userTimeOut', button);
},

Despite trying various approaches found online instead of using Ext.GlobalEvents, I haven't had much success. Ultimately, my aim is for any entity - whether it's a component, data store, application, or view - to be able to listen for and respond to these custom events.

I've managed to make it work with standard events like click or focus, but custom events are proving more challenging.

If anyone can offer guidance or assistance, it would be greatly appreciated!

Answer №1

Instead of the following code:

component.on('userTimeOut', this.onUserTimeOut);

You can use this alternative approach:

Ext.GlobalEvents.on('userTimeOut', this.onUserTimeOut, component);

This way, you can continue to use fireEvent as before. Inside your onUserTimeOut function, you will have access to the component triggering the event through the this keyword, for example: this.id.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

creation of objects using constructors in Node.js

As I delve into the world of Node.js, a burning question has arisen - how can I make a function accept multiple strings in the form of an array? Picture this scenario: export default (config: Config) => { return { target: 'https://google.com ...

How is it that deferred callbacks in JavaScript do not lead to race conditions?

I came across this snippet from the IndexedDB documentation and wanted to write something similar: var req; var store = getStore(); req = store.count(); req.onsuccess = function(evt) { console.log("success: " + evt.result); }; req.onerror = function(evt ...

Is there a way to transform a fixed parameter into a user input value and display the function's outcome on a different page?

I am in the process of developing a straightforward web application for book searching based on ISBN. The website will feature a text input field for entering an ISBN and a submit button. Essentially, a user can enter an ISBN in the designated box, click s ...

What is the best way to apply CSS styles to a child div element in Next.js?

I'm currently working on enhancing the menu bar for a website project. Utilizing nextjs for my application I am aiming to customize the look of the anchor tag, however, encountering some issues with it not rendering correctly. Here is a snippet of ...

When working with Angular 4, encountering an error like "Error: Cannot read property nativeElement

Struggling to access an element in my Angular 4 template for integrating a Google Map, I keep encountering a "cannot read property native element of undefined" error. Despite searching for solutions and trying various approaches, nothing seems to work. Th ...

Triggering a event inside a different component with react.js when a button is clicked

I am currently in the process of developing my first web application using React. It's a chat application with multiple chat rooms, and this is how the interface looks at the moment: https://i.sstatic.net/WkIvh.png My goal is to be able to click on ...

React-router can manage non-matching paths by utilizing a basic JavaScript router configuration

Is there a way to manage non-matching paths using plain JavaScript in React router configuration? const rootRoute = { component: 'div', childRoutes: [ { path: '/', component: App, childRoutes: [ requir ...

Populate object values dynamically through function invocations

Currently, I am involved in a project with a VueJS application that incorporates the following helper class and method: class BiometricMap { static get(bioType) { if (!bioType) { return BiometricMap.default(); } const bioTypes = { ...

Create your own unique Semantic UI themes using the Semantic UI theme builder, complete with support for Font Awesome classnames and the ability to preview them with the

My admiration for Semantic UI and Semantic UI React knows no bounds. Not only are they phenomenal libraries, but their documentation is truly a work of art. Yet, crafting and keeping up with themes for these components can be quite the challenge. The task ...

Implementing a codeigniter delete confirmation box with Javascript

I have tried numerous solutions on this site, but nothing seems to be working for me. I am trying to implement a pop-up window confirmation before deleting my data. Here is the code I am using: <a href="<?php echo site_url('admin/barang/delet ...

Updating reference value with a watcher using Vue 3 and the Composition API

I'm having trouble updating a ref within a watch function. My goal is to monitor changes in the length of an array, and if the new length is less than the old one, I want to update a specific ref called selectedTitle. setup() { const slots = useS ...

What is the best way to retrieve the content from the MongoDB Document in my GET request?

I encountered an issue while attempting to access the Question field within the JSON document body stored in a MongoDB database. Upon executing the GET request, the result displayed as follows: { "_readableState": { "objectMode": true, "highWaterM ...

The public folder in Node.js is known for its tendency to encounter errors

I'm facing an issue with displaying an icon on my website. Here is the current setup in my code: app.js const http = require('http'); const fs = require('fs'); const express = require('express') const path = require(&apo ...

Conceal and reveal identities with the power of react hooks

I'm just starting to work with React hooks, In my app, I want all user names to be hidden by default. However, when I click on each user, their name should be displayed. To accomplish this, I am using the show and setShow functions. Although when I tr ...

vue-router incorrectly updates parameters upon reload

One question I have is related to routing in Vue.js: // routes.js { path: '/posts', name: 'Posts', component: PostsView }, { path: '/post/:post_id', name: 'PostRead', component: PostReadView, }, { pat ...

The functionality of jQuery.hover with AJAX is malfunctioning

I am facing an issue with my jquery hover combined with $.post method. My initial intention was to create a series of select buttons where hovering would trigger a change in the image being displayed (the image path would be loaded via $.post). The image ...

Hover over the text to disable the input element and display it as a textbox

Currently, I have a situation where I have two text boxes - when text is entered into textbox1, textbox2 becomes disabled as expected. However, my second requirement is that upon disabling textbox2, hovering over it should display the message "You can ente ...

What is the purpose of the <React.StrictMode></React.StrictMode> component in React?

I stumbled upon this code snippet while practicing React, and I'm curious about its functionality. For example: const App = () => { return ( <React.StrictMode> <div id="cool-attribute"> <h1>Welcome to the Jun ...

Putting Text Inside a Video Player in HTML

Is there a way to insert text, like a Logo, into my video player? https://i.sstatic.net/CZ6Rp.png I would appreciate any help on how to achieve this. Thank you. <video width="320" height="240" controls src="video/flashtrailer.mp4"> Your browser ...

Acquire YouTube embeds from a Facebook community

Currently, I am in the process of extracting wall posts from a Facebook group feed. However, my main focus is on extracting the YouTube embed IDs only. After researching Facebook's Graph API, I have yet to find an easier method for directly extracting ...