kopia lustrzana https://github.com/backface/turtlestitch
refactored IDE >> addMessageListenerForAll(callback)
rodzic
806f9b9348
commit
639dbf2361
|
@ -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!
|
||||
|
|
17
src/gui.js
17
src/gui.js
|
@ -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];
|
||||
|
|
Ładowanie…
Reference in New Issue