Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Implements one() method for EventDispatcher to register listeners that automatically unregister after first execution.

Changes

  • Added one() method to EventDispatcher using native { once: true } option
  • Exported EventDispatcher class alongside existing instance for testability
  • Added test suite covering on(), one(), off(), and dispatch() with 11 test cases

Usage

import { eventDispatcher } from './api/events.js'

// Fires only once, auto-removes
eventDispatcher.one('tpen-project-loaded', (event) => {
    console.log('First load:', event.detail)
})

// Can still remove before firing if needed
const handler = () => {}
eventDispatcher.one('some-event', handler)
eventDispatcher.off('some-event', handler)

Enables work on #271.

Original prompt

This section details on the original issue you should resolve

<issue_title>eventDispatcher one()</issue_title>
<issue_description>Just like on() but will unregister the event after it runs the first time.

Note that once this is available, we should do #271</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 19, 2025
Copilot AI and others added 2 commits December 19, 2025 02:32
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Copilot AI changed the title [WIP] Add eventDispatcher one() method for one-time events Add EventDispatcher.one() for auto-unregistering listeners Dec 19, 2025
Copilot AI requested a review from cubap December 19, 2025 02:36
@cubap cubap marked this pull request as ready for review December 19, 2025 22:11
@cubap cubap merged commit 79e5689 into main Dec 19, 2025
1 check passed
@cubap cubap deleted the copilot/add-eventdispatcher-one-method branch December 19, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eventDispatcher one()

2 participants