# mothepro/fancy-emitter architecture

> Architecture diagram of the GitHub repository mothepro/fancy-emitter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mothepro/fancy-emitter
- Repository: https://github.com/mothepro/fancy-emitter

## Overview

##### Main Components

a) Core Components:
- SafeEmitter Class
- Emitter Class (Unsafe Emitter)
- Helper Functions Layer
- Interface Definitions Layer

b) Key Relationships:
- Inheritance relationships between Emitter types
- Helper function interactions
- Event flow patterns

**┌─ Core Components Layer ─────────────────┐**

- ┌─ Emitter Classes ──────────────┐    │

- SafeEmitter <─── Emitter     │    │

- ┘    │

- ┌─ Interface Layer ──────────────┐    │

- Listener                      │    │
- SafeListener                  │    │
- Broadcaster                   │    │
- SafeBroadcaster              │    │

- ┘    │

- ┘

**┌─ Helper Functions Layer ───────────────┐**

- bind     │ unbind   │ filter        │
- clone    │ merge    │ cancellable   │

- ┘

**┌─ Event Flow ──────────────────────────┐**

- Emitter ──► Listeners ──► Callbacks  │

- ► AsyncIterator Interface      │

- ┘

##### Important Elements to Highlight

a) Type System:
- Relationship between SafeEmitter and Emitter
- Interface hierarchy
- Demonstrate type parameter flow (T)

b) Event Flow:
- Both synchronous and asynchronous paths
- Cancellation paths
- Error propagation routes

##### Implementation Details

- The modular helper function architecture
- The clean separation between safe and unsafe variants
- The AsyncIterable implementation
- The error handling pathways

##### Key Interactions

- How events flow from activation to listeners
- How cancellation propagates
- How helper functions interact with core emitters
- How type information flows through the system

Remember to:
- Architectural patterns rather than implementation details
- Type system integration
- Both the static structure and dynamic event flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Components Layer"]
        subgraph Emitters["Emitter Classes"]
            SafeEmitter["SafeEmitter<T>"]:::core
            Emitter["Emitter<T>"]:::core
            Emitter --> SafeEmitter
        end

        subgraph Interfaces["Interface Layer"]
            Listener["Listener<T>"]:::interface
            SafeListener["SafeListener<T>"]:::interface
            Broadcaster["Broadcaster<T>"]:::interface
            SafeBroadcaster["SafeBroadcaster<T>"]:::interface
        end
    end

    subgraph Helpers["Helper Functions Layer"]
        Bind["bind()"]:::helper
        Unbind["unbind()"]:::helper
        Filter["filter()"]:::helper
        Clone["clone()"]:::helper
        Merge["merge()"]:::helper
        Cancellable["cancellable()"]:::helper
    end

    subgraph Flow["Event Flow"]
        EventSource["Event Source"]:::flow
        ListenerPool["Listener Pool"]:::flow
        Callbacks["Callbacks"]:::flow
        AsyncIter["AsyncIterator Interface"]:::flow
        
        EventSource --> ListenerPool
        ListenerPool --> Callbacks
        EventSource --> AsyncIter
    end

    %% Component Relationships
    SafeEmitter --> Listener
    SafeEmitter --> SafeListener
    Emitter --> Broadcaster
    SafeEmitter --> SafeBroadcaster

    %% Helper Relationships
    Helpers --> Emitters
    
    %% Click Events
    click SafeEmitter "https://github.com/mothepro/fancy-emitter/blob/master/src/SafeEmitter.ts"
    click Emitter "https://github.com/mothepro/fancy-emitter/blob/master/src/Emitter.ts"
    click Bind "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/bind.ts"
    click Unbind "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/unbind.ts"
    click Filter "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/filter.ts"
    click Clone "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/clone.ts"
    click Merge "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/merge.ts"
    click Cancellable "https://github.com/mothepro/fancy-emitter/blob/master/src/helpers/cancellable.ts"

    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef interface fill:#2ecc71,stroke:#27ae60,color:white
    classDef helper fill:#e67e22,stroke:#d35400,color:white
    classDef flow fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Legend
    subgraph Legend
        CoreLegend["Core Components"]:::core
        InterfaceLegend["Interfaces"]:::interface
        HelperLegend["Helpers"]:::helper
        FlowLegend["Event Flow"]:::flow
    end
```
