mirror of
https://github.com/noodlapp/noodl.git
synced 2026-01-12 23:32:53 +01:00
Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
const { Node } = require('@noodl/runtime');
|
||||
|
||||
const GlobalsNode = {
|
||||
name: 'Globals',
|
||||
shortDesc: 'A node used to communicate values across the project.',
|
||||
category: 'Utilities',
|
||||
color: 'component',
|
||||
deprecated: true, // use variable instead
|
||||
initialize: function () {
|
||||
this._internal.listeners = [];
|
||||
},
|
||||
panels: [
|
||||
{
|
||||
name: 'PortEditor',
|
||||
context: ['select', 'connectTo', 'connectFrom'],
|
||||
title: 'Globals',
|
||||
plug: 'input/output',
|
||||
type: {
|
||||
name: '*'
|
||||
}
|
||||
}
|
||||
],
|
||||
prototypeExtensions: {
|
||||
_onNodeDeleted: function () {
|
||||
Node.prototype._onNodeDeleted.call(this);
|
||||
var globalsEmitter = this.context.globalsEventEmitter;
|
||||
|
||||
for (var i = 0; i < this._internal.listeners.length; i++) {
|
||||
var listener = this._internal.listeners[i];
|
||||
globalsEmitter.removeListener(listener.name, listener.listener);
|
||||
}
|
||||
this._internal.listeners = [];
|
||||
},
|
||||
_newOutputValueReceived: {
|
||||
value: function (name) {
|
||||
this._cachedInputValues[name] = this.context.globalValues[name];
|
||||
this.flagOutputDirty(name);
|
||||
}
|
||||
},
|
||||
registerInputIfNeeded: {
|
||||
value: function (name) {
|
||||
var self = this;
|
||||
|
||||
if (this.hasInput(name)) {
|
||||
return;
|
||||
}
|
||||
this.registerInput(name, {
|
||||
set: self.context.setGlobalValue.bind(self.context, name)
|
||||
});
|
||||
}
|
||||
},
|
||||
registerOutputIfNeeded: {
|
||||
value: function (name) {
|
||||
if (this.hasOutput(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newOutputValueReceivedCallback = this._newOutputValueReceived.bind(this, name);
|
||||
|
||||
var globalsEmitter = this.context.globalsEventEmitter;
|
||||
|
||||
this._internal.listeners.push({
|
||||
name: name,
|
||||
listener: newOutputValueReceivedCallback
|
||||
});
|
||||
|
||||
globalsEmitter.on(name, newOutputValueReceivedCallback);
|
||||
|
||||
this.registerOutput(name, {
|
||||
getter: function () {
|
||||
return this.context.globalValues[name];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
node: GlobalsNode
|
||||
};
|
||||
Reference in New Issue
Block a user