@manyducks.co/dolla 2.0.0-alpha.32 → 2.0.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import type { Emitter } from "@manyducks.co/emitter";
2
2
  import type { Dolla } from "./dolla";
3
3
  import type { Store, StoreFunction } from "./store";
4
4
  interface ContextEmitterEvents {
5
- [eventName: string | symbol]: [ContextEvent<any>];
5
+ [eventName: string | symbol]: [ContextEvent, ...args: any[]];
6
6
  }
7
7
  export interface ElementContext {
8
8
  /**
@@ -39,7 +39,7 @@ export interface ElementContext {
39
39
  * Wrapping listeners is necessary because the context API's `.on` method does not pass the event name to "*" listeners while the emitter does.
40
40
  * ContextEvent objects already have the event name stored as `event.type`.
41
41
  */
42
- export type WildcardListenerMap = Map<(event: ContextEvent<any>) => void, (eventName: string | symbol, event: ContextEvent<any>) => void>;
42
+ export type WildcardListenerMap = Map<(event: ContextEvent, ...args: any[]) => void, (eventName: string | symbol, event: ContextEvent, ...args: any[]) => void>;
43
43
  export interface ComponentContext {
44
44
  /**
45
45
  * Sets a context variable and returns its value.
@@ -50,53 +50,52 @@ export interface ComponentContext {
50
50
  */
51
51
  get<T>(key: string | symbol): T | null;
52
52
  /**
53
- * Adds a listener to be called when `eventName` is emitted.
53
+ * Adds a listener to be called when an event with a matching `type` is emitted.
54
54
  */
55
- on<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
55
+ on<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
56
56
  /**
57
- * Removes a listener from the list to be called when `eventName` is emitted.
57
+ * Removes a listener from the list to be called when an event with a matching `type` is emitted.
58
58
  */
59
- off<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
59
+ off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
60
60
  /**
61
- * Adds a listener to be called when `eventName` is emitted. The listener is immediately removed after being called once.
61
+ * Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
62
62
  */
63
- once<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
63
+ once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
64
64
  /**
65
65
  * Emits a new event to all listeners.
66
66
  */
67
- emit<T = unknown>(eventName: string, detail: T): boolean;
67
+ emit<T = unknown>(type: string, ...args: any[]): boolean;
68
68
  }
69
69
  /**
70
70
  * A context capable of hosting stores.
71
71
  */
72
72
  export interface StorableContext extends ComponentContext {
73
73
  /**
74
- * Attaches a new store to this context.
74
+ * Attaches a new store to this context and returns it.
75
75
  */
76
- attachStore(store: StoreFunction<{}, any>): void;
76
+ provide<Value>(store: StoreFunction<{}, Value>): Value;
77
77
  /**
78
- * Attaches a new store to this context.
78
+ * Attaches a new store to this context and returns it.
79
79
  */
80
- attachStore(store: StoreFunction<undefined, any>): void;
80
+ provide<Value>(store: StoreFunction<undefined, Value>): Value;
81
81
  /**
82
- * Attaches a new store to this context.
82
+ * Attaches a new store to this context and returns it.
83
83
  */
84
- attachStore<Options>(store: StoreFunction<Options, any>, options: Options): void;
84
+ provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
85
85
  /**
86
86
  * Gets the closest instance of a store. Throws an error if the store isn't provided higher in the tree.
87
87
  */
88
- useStore<Value>(store: StoreFunction<any, Value>): Value;
88
+ use<Value>(store: StoreFunction<any, Value>): Value;
89
89
  }
90
90
  /**
91
91
  * An event emitted from and received by a Dolla context. These are separate from DOM events.
92
92
  */
93
- export declare class ContextEvent<T> {
93
+ export declare class ContextEvent {
94
94
  #private;
95
- type: string;
96
- detail: T;
97
- get propagationStopped(): boolean;
98
- constructor(type: string, detail: T);
99
- stopPropagation(): void;
95
+ constructor(type: string);
96
+ get type(): string;
97
+ get isStopped(): boolean;
98
+ stop(): void;
100
99
  get [Symbol.toStringTag](): string;
101
100
  }
102
101
  export {};
@@ -97,37 +97,37 @@ export declare class Dolla implements StorableContext {
97
97
  * Returns an object of all context variables stored at the app level.
98
98
  */
99
99
  /**
100
- * Adds a listener to be called when `eventName` is emitted.
100
+ * Adds a listener to be called when an event with a matching `type` is emitted.
101
101
  */
102
- on<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
102
+ on<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
103
103
  /**
104
- * Removes a listener from the list to be called when `eventName` is emitted.
104
+ * Removes a listener from the list to be called when an event with a matching `type` is emitted.
105
105
  */
106
- off<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
106
+ off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
107
107
  /**
108
- * Adds a listener to be called when `eventName` is emitted. The listener is immediately removed after being called once.
108
+ * Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
109
109
  */
110
- once<T = unknown>(eventName: string, listener: (event: ContextEvent<T>) => void): void;
110
+ once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
111
111
  /**
112
112
  * Emits a new event to all listeners.
113
113
  */
114
- emit<T = unknown>(eventName: string, detail: T): boolean;
114
+ emit<T = unknown>(type: string, ...args: any[]): boolean;
115
115
  /**
116
116
  * Attaches a new store to this context.
117
117
  */
118
- attachStore(store: StoreFunction<{}, any>): void;
118
+ provide<Value>(store: StoreFunction<{}, Value>): Value;
119
119
  /**
120
120
  * Attaches a new store to this context.
121
121
  */
122
- attachStore(store: StoreFunction<undefined, any>): void;
122
+ provide<Value>(store: StoreFunction<undefined, Value>): Value;
123
123
  /**
124
124
  * Attaches a new store to this context.
125
125
  */
126
- attachStore<Options>(store: StoreFunction<Options, any>, options: Options): void;
126
+ provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
127
127
  /**
128
128
  * Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
129
129
  */
130
- useStore<Value>(store: StoreFunction<any, Value>): Value;
130
+ use<Value>(store: StoreFunction<any, Value>): Value;
131
131
  mount(selector: string, router: Router): Promise<void>;
132
132
  mount(selector: string, view: ViewFunction<any>): Promise<void>;
133
133
  mount(element: Element, router: Router): Promise<void>;