@@ -15,8 +15,9 @@ class ActionBus {
15
15
* Subscribe to listen for new Actions of a certain type to come in, at which point the passed function
16
16
* will be called. The same Function can be subscribed multiple times.
17
17
* @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.
20
21
* @returns {boolean } True if the subscriber is added successfully, false otherwise.
21
22
*/
22
23
public subscribe ( action : typeof Action | number , fn : Function ) : boolean {
@@ -35,8 +36,9 @@ class ActionBus {
35
36
* Unsubscribe to stop listening for a type of Action on a specific Function. Will only unsubscribe the Function
36
37
* once, so if the passed Function was subscribed multiple times, you will need to unsubscribe multiple times.
37
38
* @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.
40
42
* @returns {boolean } True if the subscriber is added successfully, false otherwise. Returns true if the
41
43
* passed Function was never subscribed to the passed Action in the first place.
42
44
*/
@@ -61,13 +63,14 @@ class ActionBus {
61
63
/**
62
64
* Publish a new Action to this ActionBus, notifying all Functions subscribed to the type of Action published.
63
65
* @param action {Action} The action to publish. Should be non-null.
66
+ * @param args {Object[]} Arbitrary arguments to pass to the subscriber
64
67
*/
65
- public publish ( action : Action ) : void {
68
+ public publish ( action : Action , ... args : Object [ ] ) : void {
66
69
if ( action == null || this . subscribers [ action . id ] == null ) {
67
70
return
68
71
}
69
72
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 )
71
74
}
72
75
}
73
76
}
0 commit comments