Skip to content

Commit 98892ec

Browse files
committed
Added ability to pass arbitrary arguments to publisher
1 parent 0919c1c commit 98892ec

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

actions/ActionBus.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class ActionBus {
1515
* Subscribe to listen for new Actions of a certain type to come in, at which point the passed function
1616
* will be called. The same Function can be subscribed multiple times.
1717
* @param action {typeof Action|number} The Action type to listen for. Can be an Action class, or an Action ID.
18-
* @param fn {Function} The function to be called when the Action is received. Should be non-null. Should take
19-
* one argument, which is the Action.
18+
* @param fn {Function} The function to be called when the Action is received. Should be non-null. Should take at
19+
* least one argument, which is the Action. Further arbitrary "rest" arguments can be passed to {@link publish},
20+
* which can be received by this function.
2021
* @returns {boolean} True if the subscriber is added successfully, false otherwise.
2122
*/
2223
public subscribe(action: typeof Action|number, fn: Function) : boolean {
@@ -35,8 +36,9 @@ class ActionBus {
3536
* Unsubscribe to stop listening for a type of Action on a specific Function. Will only unsubscribe the Function
3637
* once, so if the passed Function was subscribed multiple times, you will need to unsubscribe multiple times.
3738
* @param action {typeof Action|number} The Action type to listen for. Can be an Action class, or an Action ID.
38-
* @param fn {Function} The function to be called when the Action is received. Should be non-null. Should take
39-
* one argument, which is the Action.
39+
* @param fn {Function} The function to be called when the Action is received. Should be non-null. Should take at
40+
* least one argument, which is the Action. Further arbitrary "rest" arguments can be passed to {@link publish},
41+
* which can be received by this function.
4042
* @returns {boolean} True if the subscriber is added successfully, false otherwise. Returns true if the
4143
* passed Function was never subscribed to the passed Action in the first place.
4244
*/
@@ -61,13 +63,14 @@ class ActionBus {
6163
/**
6264
* Publish a new Action to this ActionBus, notifying all Functions subscribed to the type of Action published.
6365
* @param action {Action} The action to publish. Should be non-null.
66+
* @param args {Object[]} Arbitrary arguments to pass to the subscriber
6467
*/
65-
public publish(action: Action) : void {
68+
public publish(action: Action, ... args: Object[]) : void {
6669
if(action == null || this.subscribers[action.id] == null) {
6770
return
6871
}
6972
for(let i = 0; i < this.subscribers[action.id].length; i++) {
70-
this.subscribers[action.id][i](action)
73+
this.subscribers[action.id][i](action, ...args)
7174
}
7275
}
7376
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@quickplaymod/quickplay-actions-js",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Quickplay's central Action controller, written in TypeScript.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)