General improvements

Improve explanatory comments, correct typings, make param names consistent, and simplify execute block.
This commit is contained in:
Iván Ovejero 2022-06-28 15:27:25 +02:00
commit 82b2552d10
4 changed files with 36 additions and 42 deletions

View file

@ -10,20 +10,18 @@ export class ExampleNode implements INodeType {
description: 'Basic Example Node',
defaults: {
name: 'Example Node',
color: '#772244',
},
inputs: ['main'],
outputs: ['main'],
properties: [
// Node properties which the user gets displayed and
// can change on the node.
// Node properties that the user can see and change on the node.
{
displayName: 'My String',
name: 'myString',
type: 'string',
default: '',
placeholder: 'Placeholder value',
description: 'The description text',
description: 'This is a description',
},
],
};
@ -31,15 +29,12 @@ export class ExampleNode implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
let item: INodeExecutionData;
let myString: string;
// Iterates over all input items and add the key "myString" with the
// value the parameter "myString" resolves to.
// (This could be a different value for each item in case it contains an expression)
// The node iterates over all input items and adds the key "myString" with the
// value the parameter "myString" resolves to. (This could be a different value
// for each item in case it contains an expression.)
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
myString = this.getNodeParameter('myString', itemIndex, '') as string;
item = items[itemIndex];
const myString = this.getNodeParameter('myString', itemIndex, '') as string;
const item = items[itemIndex];
item.json['myString'] = myString;
}