xiaohongshu
xiaohongshu
custom-global-events
Guidelines for creating/using the app’s typed global events system.
Full skill instructions
Global events are used for cross-component communication without React context dependencies, allowing for simple function calls to trigger events across different parts of the application.
Global events are used for cross-component communication without React context dependencies, allowing for simple function calls to trigger events across different parts of the application.
The global events system lives at global-event.tsx and is built on a typed Event subclass (XCustomEvent).
It exposes:
global_event_Event: the canonical type map of event keys → detail payload typesglobal_event_dispatch(event, payload): dispatch a typed event (works outside React)global_event_listen(event, handler, options?): listen with typed handler (works outside React)useGlobalEvent(event, handler): React hook for subscriptions with stale-closure protectionEvent keys are string literals using the pattern:
(module::event_name), for example ai_chat::open_canvas.
When the user requests a new global event, you must:
Add the new event key to the global_event_Event map in global-event.tsx.
Example:
export class global_event_Event extends XCustomEvent<{
"ai_chat::open_canvas": {
pageId: app_convex_Id<"pages">;
mode: "diff" | "editor";
modifiedContent?: string;
threadId: string;
};
"ai_chat::open_canvas_by_path": {
path: string;
};
"docs::focus_path": {
path: string;
};
}> {}
All supported global event keys must be declared in that global_event_Event type map. Do not introduce ad-hoc stringly-typed events elsewhere.
Prefer global_event_dispatch / global_event_listen / useGlobalEvent rather than calling window.dispatchEvent(new CustomEvent(...)) directly.
Use useGlobalEvent(eventName, handler) to subscribe. The handler receives a typed event object, and the payload is on event.detail.
Example (from canvas.tsx):
useGlobalEvent("ai_chat::open_canvas", (e) => {
const payload = e.detail;
// payload.pageId, payload.mode, payload.modifiedContent, payload.threadId
});
Use global_event_listen directly when you need to wire AbortController, or you are outside React.
const controller = new AbortController();
const cleanup = global_event_listen(
"ai_chat::open_canvas_by_path",
(e) => {
console.info("path:", e.detail.path);
},
{ signal: controller.signal },
);
// later:
controller.abort();
cleanup();
Use global_event_dispatch(eventName, payload) from anywhere client-side.
Example (from app-ai-chat.tsx):
global_event_dispatch("ai_chat::open_canvas_by_path", { path: args.path });
Handlers receive the typed event object, not the payload directly:
useGlobalEvent("ai_chat::open_canvas", (e) => {
const payload = e.detail;
});
XCustomEvent in utils.tsuseLiveRef in utils-hooks.tsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience