Skip to content

Refactor DispatchEvent to use enum for type-safety #403

@tusharmath

Description

@tusharmath

Current Implementation

Currently, the DispatchEvent struct uses string-based event types:

pub struct DispatchEvent {
    pub id: String,
    pub name: String,
    pub value: String,
    pub timestamp: String,
}

This approach has several drawbacks:

  • No type safety for event types
  • String comparison for event matching
  • No structured data for specific event types
  • Difficult to track all available event types

Proposed Change

Refactor DispatchEvent to use an enum for representing different event types:

pub enum EventType {
    // Internal pre-defined events
    UserTaskInit(String),
    UserTaskUpdate(String),
    // Other internal events...
    
    // For custom events
    Custom {
        name: String,
        value: String,
    }
}

pub struct DispatchEvent {
    pub id: String,
    pub event_type: EventType,
    pub timestamp: String,
}

Benefits

  1. Type Safety: Compiler can enforce correctness for event handling
  2. Improved API: More intuitive API with proper type information
  3. Discoverability: All available event types visible in the enum
  4. Structured Data: Each event type can carry appropriate data
  5. Better IDE Support: Auto-completion for event types

Implementation Notes

  • Update all places that create or consume events
  • Maintain backward compatibility where needed
  • Update documentation and tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureBrand new functionality, features, pages, workflows, endpoints, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions