Skip to content

Commit 8ddbabc

Browse files
committed
feat(scene): add EventComposer support to extend method
- Add EventComposer overload to extend() for proper type inference - Implement runtime detection to distinguish EventComposer from Plugin - Check for compose/run methods and absence of _ property to identify EventComposer - Preserve existing Plugin extend functionality - Update type definitions to merge global exposed properties and derives
1 parent d978588 commit 8ddbabc

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/scene.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ContextType,
99
type DeriveDefinitions,
1010
type ErrorDefinitions,
11+
type EventComposer,
1112
type Handler,
1213
type MaybeArray,
1314
type MaybePromise,
@@ -101,9 +102,15 @@ export class Scene<
101102
>;
102103
}
103104

104-
/**
105-
*
106-
* */
105+
extend<UExposed extends object, UDerives extends Record<string, object>>(
106+
composer: EventComposer<any, any, any, any, UExposed, UDerives, any>,
107+
): Scene<
108+
Params,
109+
Errors,
110+
State,
111+
Derives & { global: UExposed } & UDerives
112+
>;
113+
107114
extend<NewPlugin extends AnyPlugin>(
108115
plugin: NewPlugin,
109116
): Scene<
@@ -112,8 +119,24 @@ export class Scene<
112119
State,
113120
// @ts-expect-error
114121
Derives & NewPlugin["_"]["Derives"]
115-
> {
116-
this["~"].composer.extend(plugin);
122+
>;
123+
124+
extend(
125+
pluginOrComposer:
126+
| AnyPlugin
127+
| EventComposer<any, any, any, any, any, any, any>,
128+
): this {
129+
if (
130+
"compose" in pluginOrComposer &&
131+
"run" in pluginOrComposer &&
132+
!("_" in pluginOrComposer)
133+
) {
134+
// EventComposer: deduplication is handled internally via composer["~"].extended
135+
this["~"].composer.extend(pluginOrComposer as any);
136+
} else {
137+
// AnyPlugin: Plugin exposes get "~"() that duck-types as Composer
138+
this["~"].composer.extend(pluginOrComposer as any);
139+
}
117140

118141
return this;
119142
}

0 commit comments

Comments
 (0)