You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to develop a message function between users with GUN. The messages are stored in gunDB and displayed on the page when a peer account is selected. Here is what I'm trying to do:
For example, when the user selects Alice in the select box, the messages between the user and Alice will be displayed. Any subsequent message updates will also be shown as the data in the node is subscribed by the gun.get('chat').get(peer).map().once(cb) function. However, when the user switches to Bob and then back to Alice, gun.get('chat').get(peer).map().once(cb) (where peer is Alice) is called twice in total and the listener for message updates is created twice. Therefore, when there are new messages sent, the messages will be shown twice instead of only once.
Is there a feature to stop .map() function to subscribe to data updates in a node? I've tried to create a variable prevPeer to store the previous peer and call gun.get('chat').get(prevPeer).off() at the beginning of displayMessage() but nothing has changed.
The text was updated successfully, but these errors were encountered:
chain.off() should remove all listeners at that chain & underneath, rather aggressively. .on(data, key, msg, event){ event.off() should remove that one individual listener. It seems like neither of these are working? I wonder if it is because .map() creates a type of special sub-chain that is not accessible to chain.off() tho it should be... someone willing to debug against https://github.com/amark/gun/blob/master/gun.js#L1290-L1295 ?
I have been trying to develop a message function between users with GUN. The messages are stored in gunDB and displayed on the page when a peer account is selected. Here is what I'm trying to do:
For example, when the user selects Alice in the select box, the messages between the user and Alice will be displayed. Any subsequent message updates will also be shown as the data in the node is subscribed by the
gun.get('chat').get(peer).map().once(cb)
function. However, when the user switches to Bob and then back to Alice,gun.get('chat').get(peer).map().once(cb)
(where peer is Alice) is called twice in total and the listener for message updates is created twice. Therefore, when there are new messages sent, the messages will be shown twice instead of only once.Is there a feature to stop
.map()
function to subscribe to data updates in a node? I've tried to create a variableprevPeer
to store the previous peer and callgun.get('chat').get(prevPeer).off()
at the beginning ofdisplayMessage()
but nothing has changed.The text was updated successfully, but these errors were encountered: