Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

307
Visualizações
How do I make a node-red node that is already on a flow obey the default values of a newly-added property?

Initially, this is my node configurations.

RED.nodes.registerType('HelloWorld', {
  category: 'HelloWorld',
  defaults: {
    firstProp: {value: false}
  },
}

This helloworld node is then placed on a flow.

Then, I added another property, secondProp to the configuration and restart node-red.

RED.nodes.registerType('HelloWorld', {
  category: 'HelloWorld',
  defaults: {
    firstProp: {value: false}
    secondProp: {value: true}
  },
}

When I export the flow, I notice the secondProp is set to false. I had expected it to be set to the default which is true

[
{
    "id": "04abe6r5baqs16dc",
    ...
    "firstProp": false,
    "secondProp": false, //expected it to be true
    "x": 290,
    "y": 360
}
]

May I know how do I resolve this and ensure the existing custom nodes on the flow obey the default values of a newly-added property?

NOTE:

When I pull the custom node and place it on the flow, it doesn't have this issue i.e., the secondProp value is true.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One of the node-red maintainer commented

The flow file is not modified just because you modified the custom node src. You would have to handle any in-place upgrades in oneditprepare. This is normal behaviour as far as I can see.

So as a workaround, we can only do like this

RED.nodes.registerType('HelloWorld', {
  category: 'HelloWorld',
  defaults: {
    firstProp: {value: false}
  },
  oneditprepare: {
    if (this.secondProp === undefined) {
      this.secondProp = true;
    }
  }
}

Note that this will require us to open the edit dialog of the node for it to take effect.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda