added ability to add general message listeners for "any" message

pull/89/head
jmoenig 2019-12-16 08:42:57 +01:00
rodzic e79e159921
commit ebc456d5f1
4 zmienionych plików z 22 dodań i 7 usunięć

Wyświetl plik

@ -16,6 +16,9 @@
* NEW Slovak translation, thanks, Peter Lukacovic
* German
### 2019-12-16
* gui, objects: added ability to add general message listeners for "any" message
### 2019-12-15
* gui, threads: new Snap! API: programmatically broadcast messages and optionally wait from outside Snap!
* gui: added global variable access methods to the new Snap! API

Wyświetl plik

@ -8,8 +8,8 @@
<script type="text/javascript" src="src/widgets.js?version=2019-10-16"></script>
<script type="text/javascript" src="src/blocks.js?version=2019-12-13"></script>
<script type="text/javascript" src="src/threads.js?version=2019-12-15"></script>
<script type="text/javascript" src="src/objects.js?version=2019-12-15"></script>
<script type="text/javascript" src="src/gui.js?version=2019-12-15"></script>
<script type="text/javascript" src="src/objects.js?version=2019-12-16"></script>
<script type="text/javascript" src="src/gui.js?version=2019-12-16"></script>
<script type="text/javascript" src="src/paint.js?version=2019-06-27"></script>
<script type="text/javascript" src="src/lists.js?version=2019-12-08"></script>
<script type="text/javascript" src="src/byob.js?version=2019-07-12"></script>

Wyświetl plik

@ -79,7 +79,7 @@ BlockEditorMorph, BlockDialogMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2019-December-15';
modules.gui = '2019-December-16';
// Declarations
@ -6102,6 +6102,9 @@ IDE_Morph.prototype.broadcast = function(message, callback) {
));
});
});
(this.stage.messageCallbacks[''] || []).forEach(function (callback) {
callback(message);
});
(this.stage.messageCallbacks[message] || []).forEach(function (callback) {
callback();
});
@ -6111,9 +6114,15 @@ 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
// 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
var funcs;
if (!isString(message)) {
if (message instanceof Function && isNil(callback)) {
callback = message;
message = '';
} else if (!isString(message)) {
throw new Error('message must be a String');
}
funcs = this.stage.messageCallbacks[message];

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/
modules.threads = '2019-December-15';
modules.threads = '2019-December-16';
var ThreadManager;
var Process;
@ -3180,8 +3180,11 @@ Process.prototype.doBroadcast = function (message) {
});
}
});
(stage.messageCallbacks[''] || []).forEach(function (callback) {
callback(msg); // for "any" message, pass it along as argument
});
(stage.messageCallbacks[msg] || []).forEach(function (callback) {
callback();
callback(); // for a particular message
});
}
return procs;