msg transport - by reference issue
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 35/100
- Type d'issue
- Documentation
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- javascript
- Domaine
- documentation
Piste de recherche
Examinez la section « receiving messages » de la documentation de creating-nodes/node-js ainsi que la sous-section « Writing a function » de writing-functions. Vérifiez les affirmations de l’issue concernant les références aux messages, RED.util.cloneMessage(msg) et la conservation des propriétés avant de déterminer quelles indications sont exactes. Le travail est terminé lorsque les deux sections expliquent clairement le comportement et ses conséquences sans se contredire.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Following discussions elsewhere I made a node called "node-red-contrib-diode" after discovering something I should have known already - that messages are passed by referrence, not by value. This can cause issues as someone may use a message twice in a function - sending it out with node-send and then re-using it. Should the receiving function or node alter the message in any way, because it was sent by reference - this can actually damage the original message. "diode" stops this - but I think this should be clearly pointed out in the documentation.
I found this...
ttp://nodered.org/docs/creating-nodes/node-js
Section "receiving messages"
Suggest you add: "Please note that a reference to the original message is passed here. Altering that message could, in edge cases, affect the calling function."
http://nodered.org/docs/writing-functions
Section "Writing functions"
Subsection "Writing a function"...
You say:
"The returned message object does not need to be same object as was passed in; the function can construct a completely new object before returning it. For example:
var newMsg = { payload: msg.payload.length };
return newMsg;
Note: constructing a new message object will lose any message properties of the received message. This will break some flows, for example the HTTP In/Response flow requires the msg.req and msg.res properties to be preserved end-to-end. In general, function nodes should return the message object they were passed having made any changes to its properties."
So firstly - why would construction a new message lose properties of the old. Using the code DaveCJ provided:
var newMsg = RED.util.cloneMessage(msg);
does not lose any of the original message - I tested it... so you seem to be saying NOT to make a new object - but you don't warn of the consequences. Why not change that example to use the code above which will ensure everything is copied across - scrap the warning that data could be lost and instead tell readers that this might slightly increase overhead - but will eliminate any chance of interaction with the original message.
In my diode node - here you see the unprocessed output - and the output through the node - they are identical down to the msgID - except for the payload which I deliberately altered to show the feedback effect.
msg : Object
{ _msgid: "e5a704f0.1a58f8", topic: "", payload: "goodbye", blah: "fred" }
6/26/2017, 2:31:23 PMnode: d9f3747f.7ef978
msg : Object
{ _msgid: "e5a704f0.1a58f8", topic: "", payload: "hello", blah: "fred" }
Hope this is helpful.
- Langage dominant
- JavaScript
- Étoiles
- 118
- Forks
- 161
- Merge moyen
- 8 h 18 min
- PR mergées (30 j)
- 4
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de node-red/node-red.github.io
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 68/100
node-red/node-red.github.io#327 ·
-
docs/getting-started/local.md: npm command line is now deprecated, use --location=global not -g Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
node-red/node-red.github.io#280 · 1 commentaire ·
-
Website updates for Node-RED 5.0 Ouverte
node-red/node-red.github.io#416 · 1 réaction · 1 personne assignée ·
-
Difficulté 1/5 1-3 heures Accessibilité débutants 50/100
node-red/node-red.github.io#384 ·
-
node-red/node-red.github.io#382 · 1 commentaire · 1 personne assignée ·
Toutes les issues de node-red/node-red.github.io
Issues similaires
-
Difficulté 1/5 1-3 heures Accessibilité débutants 86/100
DavidAnson/markdownlint-cli2#940 ·
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
githubnext/gh-aw-workshop#3692 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
-
Add: BuyPass TV Ouvertechannels:add check:passed
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
S: triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100