feat(runtime): Add "Switched" signal output on the Switch node (#58)

This commit is contained in:
Eric Tuvesson
2024-07-19 15:02:49 +02:00
committed by GitHub
parent c508e15546
commit 46e2efa576

View File

@@ -4,7 +4,7 @@ const Switch = {
name: 'Switch',
docs: 'https://docs.noodl.net/nodes/logic/switch',
category: 'Logic',
initialize: function () {
initialize() {
this._internal.state = false;
this._internal.initialized = false;
},
@@ -15,7 +15,7 @@ const Switch = {
on: {
displayName: 'On',
group: 'Change State',
valueChangedToTrue: function () {
valueChangedToTrue() {
if (this._internal.state === true) {
return;
}
@@ -27,7 +27,7 @@ const Switch = {
off: {
displayName: 'Off',
group: 'Change State',
valueChangedToTrue: function () {
valueChangedToTrue() {
if (this._internal.state === false) {
return;
}
@@ -39,7 +39,7 @@ const Switch = {
flip: {
displayName: 'Flip',
group: 'Change State',
valueChangedToTrue: function () {
valueChangedToTrue() {
this._internal.state = !this._internal.state;
this.flagOutputDirty('state');
this.emitSignals();
@@ -50,7 +50,7 @@ const Switch = {
displayName: 'State',
group: 'General',
default: false,
set: function (value) {
set(value) {
this._internal.state = !!value;
this.flagOutputDirty('state');
this.emitSignals();
@@ -61,10 +61,15 @@ const Switch = {
state: {
type: 'boolean',
displayName: 'Current State',
getter: function () {
getter() {
return this._internal.state;
}
},
switched: {
displayName: 'Switched',
type: 'signal',
group: 'Signals'
},
switchedToOn: {
displayName: 'Switched To On',
type: 'signal',
@@ -77,12 +82,13 @@ const Switch = {
}
},
prototypeExtensions: {
emitSignals: function () {
emitSignals() {
if (this._internal.state === true) {
this.sendSignalOnOutput('switchedToOn');
} else {
this.sendSignalOnOutput('switchedToOff');
}
this.sendSignalOnOutput('switched');
}
}
};