mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
373267c53b
This introduces a much more consistent set of events within the editor for whenever a element is added, removed or modified. The events emited on the `RED.events` event system. The event names take the form: `"<thing>:<action>"`. `<thing>` can be one of: - nodes - flows - subflows - groups - links `<action>` can be one of: - add - remove - change The payload of the events is the object in question. There is also: - flows:reorder - when tabs are reordered. Payload is array of flow ids. - workspace:clear - when the workspace is emptied - part of switching projects The `nodes:change` event was already used by RED.nodes.dirty() to cause the Deploy button to become active. This renames that event to: - workspace:dirty - Payload is boolean flag for the dirty state This commit also updates the Palette to use the subflows:change event to only redraw subflows that have actually changed rather than refresh them all whenever one of them *might* have changed. This removes a noticable flicker of the icon which was needlessly being redrawn.
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
**/
|
|
|
|
RED.events = (function() {
|
|
var handlers = {};
|
|
|
|
function on(evt,func) {
|
|
handlers[evt] = handlers[evt]||[];
|
|
handlers[evt].push(func);
|
|
}
|
|
function off(evt,func) {
|
|
var handler = handlers[evt];
|
|
if (handler) {
|
|
for (var i=0;i<handler.length;i++) {
|
|
if (handler[i] === func) {
|
|
handler.splice(i,1);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function emit() {
|
|
var evt = arguments[0]
|
|
var args = Array.prototype.slice.call(arguments,1);
|
|
if (RED.events.DEBUG) {
|
|
console.log(evt,args);
|
|
}
|
|
if (handlers[evt]) {
|
|
for (var i=0;i<handlers[evt].length;i++) {
|
|
try {
|
|
handlers[evt][i].apply(null, args);
|
|
} catch(err) {
|
|
console.log("RED.events.emit error: ["+evt+"] "+(err.toString()));
|
|
console.log(err);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return {
|
|
on: on,
|
|
off: off,
|
|
emit: emit
|
|
}
|
|
})();
|