// Basic event listener
const button = document.getElementById('myButton');
button.addEventListener('click', function(event) {
console.log('Button clicked!');
console.log('Event type:', event.type);
-- Publisher: Send notification
NOTIFY new_order, 'Order #12345 created';
-- Subscriber: Listen for notifications
LISTEN new_order;
<?php
namespace App\Observers;
use App\Events\PostPublished;
use App\Models\Post;
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.mail import send_mail
from .models import User, Profile
export type EventMap = Record<string, unknown[]>;
type Listener<Args extends unknown[]> = (...args: Args) => void;
export class TypedEmitter<Events extends EventMap> {
private listeners = new Map<keyof Events, Set<Listener<any>>>();
package events
import "encoding/json"
type Envelope struct {
Type string `json:"type"`
<?php
namespace App\Events;
use App\Models\Order;
use Illuminate\Broadcasting\PrivateChannel;
export interface AnalyticsEvent {
name: string;
props?: Record<string, unknown>;
ts: number;
}
<?php
namespace App\Providers;
use App\Events\OrderPlaced;
use App\Listeners\DecrementInventory;
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.context.annotation.Bean;
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
import { RefObject, useEffect, useRef } from "react";
type Handler = (event: MouseEvent | TouchEvent) => void;
export function useClickOutside<T extends HTMLElement>(
ref: RefObject<T>,