Skip to content

feat: new ya.emit() API#2653

Merged
sxyazi merged 1 commit intomainfrom
pr-277a54d6
Apr 21, 2025
Merged

feat: new ya.emit() API#2653
sxyazi merged 1 commit intomainfrom
pr-277a54d6

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented Apr 21, 2025

This PR introduces a new ya.emit() API to address:

  • The existing ya.mgr_emit() API can only emit events to [manager].
  • The existing ya.app_emit() and ya.input_emit() can be used to emit events to [app] and [input], but they are private and undocumented APIs.
  • There is no available API to send events to [tasks], [spot], [pick], [confirm], [cmp], or [help].

The first parameter of ya.emit() is the event ID in the format component:event, where the component: part is optional and defaults to [manager], for example:

ya.emit("arrow", { 1 })  -- Emit an "arrow" event to [manager]
ya.emit("cmp:arrow", { 1 })  -- Emit an "arrow" event to [cmp]

The second parameter is the parameters for the event.

Deprecated

ya.mgr_emit() is deprecated

ya.emit() can be used as a direct replacement for ya.mgr_emit():

- ya.mgr_emit("arrow", { 1 })
+ ya.emit("arrow", { 1 })

Since ya.mgr_emit() is a public and widely used API, it will remain available for a long time and will later include a deprecation warning before eventually being removed.

ya.app_emit() and ya.input_emit() are deprecated

ya.app_emit() and ya.input_emit() are private and undocumented APIs. However, since they have been around for a long time, this PR marks them as deprecated and they will be removed in the future.

- ya.app_emit("resize", {})
+ ya.emit("app:resize", {})
- ya.input_emit("close", {})
+ ya.emit("input:close", {})

@sxyazi sxyazi requested a review from Copilot April 21, 2025 11:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new ya.emit() API to consolidate event emission for various components and deprecate legacy APIs.

  • Adds new command creation helper methods with improved error handling in Cmd
  • Introduces the "emit" API in the Lua binding and deprecates ya.app_emit() and ya.input_emit()
  • Updates the Lua API composition to register the new "emit" function alongside legacy functions

Reviewed Changes

Copilot reviewed 3 out of 19 changed files in this pull request and generated no comments.

File Description
yazi-shared/src/event/cmd.rs Adds new() and new_or() with refined error propagation
yazi-plugin/src/utils/utils.rs Registers the new "emit" command for event dispatch
yazi-plugin/src/utils/call.rs Implements the new "emit" function and deprecates older APIs
Files not reviewed (16)
  • yazi-plugin/preset/components/current.lua: Language not supported
  • yazi-plugin/preset/components/parent.lua: Language not supported
  • yazi-plugin/preset/components/preview.lua: Language not supported
  • yazi-plugin/preset/plugins/archive.lua: Language not supported
  • yazi-plugin/preset/plugins/code.lua: Language not supported
  • yazi-plugin/preset/plugins/dds.lua: Language not supported
  • yazi-plugin/preset/plugins/empty.lua: Language not supported
  • yazi-plugin/preset/plugins/extract.lua: Language not supported
  • yazi-plugin/preset/plugins/folder.lua: Language not supported
  • yazi-plugin/preset/plugins/fzf.lua: Language not supported
  • yazi-plugin/preset/plugins/json.lua: Language not supported
  • yazi-plugin/preset/plugins/mime.lua: Language not supported
  • yazi-plugin/preset/plugins/pdf.lua: Language not supported
  • yazi-plugin/preset/plugins/session.lua: Language not supported
  • yazi-plugin/preset/plugins/video.lua: Language not supported
  • yazi-plugin/preset/plugins/zoxide.lua: Language not supported

@sxyazi sxyazi merged commit 8327826 into main Apr 21, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-277a54d6 branch April 21, 2025 11:28
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants