Skip to content

Commit a4f8705

Browse files
Fn inheritance
1 parent 95c00f8 commit a4f8705

File tree

5 files changed

+40
-42
lines changed

5 files changed

+40
-42
lines changed

packages/sources/node/src/lib/push.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function createPush(
1515
instance: SourceNode.Instance,
1616
handleCommand: SourceNode.HandleCommand,
1717
handleEvent: SourceNode.HandleEvent,
18-
): Elb.Fn<Promise<Elb.PushResult>> {
18+
): Elb.Fn {
1919
const push = async (
20-
nameOrEvent: string | WalkerOS.DeepPartialEvent,
21-
data?: Elb.PushData,
20+
nameOrEvent: unknown,
21+
data: Elb.PushData = {},
2222
options?: Elb.PushOptions,
2323
) => {
2424
let result: Elb.PushResult = {
@@ -30,10 +30,10 @@ export function createPush(
3030

3131
return await tryCatchAsync(
3232
async (
33-
nameOrEvent: string | WalkerOS.DeepPartialEvent,
34-
data?: Elb.PushData,
33+
nameOrEvent: unknown,
34+
data: Elb.PushData,
3535
options?: Elb.PushOptions,
36-
): Promise<Elb.PushResult> => {
36+
): Elb.Return => {
3737
const { event, command } = createEventOrCommand(
3838
instance,
3939
nameOrEvent,
@@ -208,8 +208,8 @@ export async function pushToDestinations(
208208

209209
function createEventOrCommand(
210210
instance: SourceNode.Instance,
211-
nameOrEvent: string | WalkerOS.DeepPartialEvent,
212-
pushData: unknown,
211+
nameOrEvent: unknown,
212+
pushData: Elb.PushData,
213213
): { event?: WalkerOS.Event; command?: string } {
214214
// Determine the partial event
215215
const partialEvent: WalkerOS.PartialEvent = isSameType(

packages/sources/node/src/types/elb.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import type { Elb, WalkerOS } from '@elbwalker/types';
22
import { DestinationNode, SourceNode } from '.';
33

4-
export interface Fn<R = Return>
5-
extends Elb.Fn<R>,
6-
Arguments<R>,
4+
export interface Fn<R = Return, D = PushData, O = PushOptions>
5+
extends Elb.Fn<R, D, O>,
76
CommandDestination<R>,
87
CommandRun<R> {}
98

10-
export type Arguments<R = Return> = (
11-
name: string,
12-
data?: PushData,
13-
options?: PushOptions,
14-
) => R;
15-
169
export type CommandDestination<R = void> = (
1710
event: 'walker destination',
1811
destination: DestinationNode.Destination | DestinationNode.DestinationInit,
@@ -23,6 +16,7 @@ export type CommandRun<R = void> = (event: 'walker run') => R;
2316
export type PushData =
2417
| Elb.PushData
2518
| DestinationNode.Destination
19+
| DestinationNode.DestinationInit
2620
| Partial<SourceNode.State>;
2721

2822
export type PushOptions = Elb.PushOptions | DestinationNode.Config;

packages/sources/walkerjs/src/types/elb.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import type { Elb, WalkerOS } from '@elbwalker/types';
22
import type { On, DestinationWeb, Walker, SourceWalkerjs } from '.';
33

4-
export interface Fn<R = void>
5-
extends Elb.Fn<R>,
6-
Arguments<R>,
4+
export interface Fn<R = void, D = PushData, O = PushOptions, C = PushContext>
5+
extends Elb.Fn<R, D, O, C>,
76
CommandInit<R>,
87
CommandDestination<R>,
98
CommandOn<R>,
109
CommandRun<R> {}
1110

12-
export type Arguments<R = void> = (
13-
event?: string,
14-
data?: PushData,
15-
options?: PushOptions,
16-
context?: PushContext,
17-
nested?: WalkerOS.Entities,
18-
custom?: WalkerOS.Properties,
19-
) => R;
20-
2111
export type CommandInit<R = void> = (
2212
event: 'walker init',
2313
scope: Scope | Scope[],
@@ -40,16 +30,7 @@ export type CommandOn<R = void> = (
4030
rules: WalkerOS.SingleOrArray<On.ConsentConfig>,
4131
) => R;
4232

43-
type FnParameters<T> = T extends (...args: unknown[]) => unknown
44-
? Parameters<T>[number]
45-
: never;
46-
47-
export type Layer = Array<
48-
| IArguments
49-
| WalkerOS.DeepPartialEvent
50-
| FnParameters<Fn[keyof Fn]>
51-
| Parameters<Arguments>[number]
52-
>;
33+
export type Layer = Elb.Layer;
5334

5435
export type PushData =
5536
| Elb.PushData

packages/types/src/elb.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import type { Hooks, WalkerOS } from '.';
22

3-
export interface Fn<R = void>
3+
export interface Fn<R = void, D = PushData, O = PushOptions, C = PushContext>
44
extends Event<R>,
5+
Arguments<R, D, O, C>,
56
CommandConfig<R>,
67
CommandConsent<R>,
78
CommandHook<R>,
89
CommandUser<R> {}
910

11+
export type Arguments<
12+
R = void,
13+
D = PushData,
14+
O = PushOptions,
15+
C = PushContext,
16+
> = (
17+
event?: string,
18+
data?: D,
19+
options?: O,
20+
context?: C,
21+
nested?: WalkerOS.Entities,
22+
custom?: WalkerOS.Properties,
23+
) => R;
1024
export type CommandConfig<R = void> = (
1125
event: 'walker config',
1226
config: Partial<WalkerOS.Config>,
@@ -37,3 +51,14 @@ export type PushData =
3751
export type PushOptions = Hooks.AnyFunction | object;
3852

3953
export type PushContext = WalkerOS.OrderedProperties;
54+
55+
type FnParameters<T> = T extends (...args: unknown[]) => unknown
56+
? Parameters<T>[number]
57+
: never;
58+
59+
export type Layer = Array<
60+
| IArguments
61+
| WalkerOS.DeepPartialEvent
62+
| FnParameters<Fn[keyof Fn]>
63+
| Parameters<Arguments>[number]
64+
>;

packages/utils/src/web/elb.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { Elb } from '@elbwalker/types';
22

3-
export type ElbLayer = Array<IArguments>;
4-
53
export const elb: Elb.Fn = function () {
64
const w = window as unknown as Record<string, unknown[]>;
75
// eslint-disable-next-line prefer-rest-params

0 commit comments

Comments
 (0)