@soundworks/core 4.0.0-alpha.13 → 4.0.0-alpha.14
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.
package/package.json
CHANGED
|
@@ -118,9 +118,18 @@ class BaseSharedStateCollection {
|
|
|
118
118
|
*
|
|
119
119
|
* @param {Function} callback - callback to execute when a state is added to
|
|
120
120
|
* the collection.
|
|
121
|
+
* @param {Function} executeListener - execute the callback with the states
|
|
122
|
+
* already present in the collection.
|
|
123
|
+
* @returns {Function} - Function that delete the registered listener.
|
|
121
124
|
*/
|
|
122
|
-
onAttach(callback) {
|
|
125
|
+
onAttach(callback, executeListener = false) {
|
|
126
|
+
if (executeListener === true) {
|
|
127
|
+
this._states.forEach(state => callback(state));
|
|
128
|
+
}
|
|
129
|
+
|
|
123
130
|
this._onAttachCallbacks.add(callback);
|
|
131
|
+
|
|
132
|
+
return () => this._onAttachCallbacks.delete(callback);
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
/**
|
|
@@ -128,9 +137,12 @@ class BaseSharedStateCollection {
|
|
|
128
137
|
*
|
|
129
138
|
* @param {Function} callback - callback to execute when a state is removed
|
|
130
139
|
* from the collection.
|
|
140
|
+
* @returns {Function} - Function that delete the registered listener.
|
|
131
141
|
*/
|
|
132
142
|
onDetach(callback) {
|
|
133
143
|
this._onDetachCallbacks.add(callback);
|
|
144
|
+
|
|
145
|
+
return () => this._onDetachCallbacks.delete(callback);
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
/**
|
|
@@ -188,7 +200,7 @@ class BaseSharedStateCollection {
|
|
|
188
200
|
}
|
|
189
201
|
|
|
190
202
|
/**
|
|
191
|
-
* Iterable API for use in `for .. of` loops
|
|
203
|
+
* Iterable API, e.g. for use in `for .. of` loops
|
|
192
204
|
*/
|
|
193
205
|
[Symbol.iterator]() {
|
|
194
206
|
let index = 0;
|