refactored IDE >> addMessageListenerForAll(callback)

pull/89/head
jmoenig 2019-12-16 10:28:49 +01:00
rodzic 806f9b9348
commit 639dbf2361
2 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -19,6 +19,7 @@
### 2019-12-16
* gui, objects: added ability to add general message listeners for "any" message
* gui: added IDE >> getMessages() to Snap! API
* gui: refactored IDE >> addMessageListenerForAll(callback)
### 2019-12-15
* gui, threads: new Snap! API: programmatically broadcast messages and optionally wait from outside Snap!

Wyświetl plik

@ -6110,19 +6110,22 @@ IDE_Morph.prototype.broadcast = function(message, callback) {
});
};
IDE_Morph.prototype.addMessageListenerForAll = function (callback) {
// associate a monadic callback with all broadcasts.
// whenever a message is broadcast the callback is called
// with the current message as argument
this.addMessageListener('', callback);
};
IDE_Morph.prototype.addMessageListener = function (message, callback) {
// associate a callback function with a broadcast message,
// whenever the message is broadcast, the callback is executed,
// you can add multiple callbacks to a message, they will be
// executed in the order you added them.
// Note: Only passing a callback or associating a callback with
// an empty string attaches the callback to "any" message, taking
// the actual message as argument
// Note: ssociating a callback with an empty string attaches the
// callback to "any" message, taking the actual message as argument
var funcs;
if (message instanceof Function && isNil(callback)) {
callback = message;
message = '';
} else if (!isString(message)) {
if (!isString(message)) {
throw new Error('message must be a String');
}
funcs = this.stage.messageCallbacks[message];