-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs with "map([cb])" and following once / on #1315
Comments
well detailed! Thank you. You're correct. Interested in adding these to the unit tests? starts around https://github.com/amark/gun/blob/master/test/common.js#L3439 , or better (since its low priority for me) trying to fix? Can do a video call if need. |
Hi @amark, |
@pwFoo thanks for trying tho. Maybe when higher priority items are off the checklist (oof... taking a long time) then can do a screen call on this piece. |
I think listeners increasing because of that
So each time it's called another listener is added? Or lines like that
or the map code if called without callback
I think it would be easier for you to fix the bug instead of explain to me how the code works. |
I started my project based on Gun / SEA to have a working base (offline first, encryption, ...). I'm not clear if Gun has reached EOS / EOL or your higher priority projects / tasks are based on Gun? Despite the bugs. Gun is an impressive project with a lot of potential. I would like to see an active support team and improved documentation / code base with comments to push Gun further. |
@pwFoo This may help.. You can work around duplicate data like so: let last
gun.get("graph").get("subgraph").on(data => {
if(data == last) return
last = data
}) However, if your code is creating multiple listeners for the same thing, it can lead to memory leaks. |
@draeder |
Anybody know what is the status on this? I just ran some additional tests, that gave curious results.... In some situations the map function will work correctly. It seem to be a timing issue. Test resultsTest1 (Works)
Test2 (Unexpected result)
Test code// test1 works
function test1(){
gun.get("test1").get("people").set({name: "Mark"}) }
gun.get("test1").get("people").map(user => {
console.log("MAP DEBUG 1", user); return user
}).once((user, id) => console.log(id, user));
}
// test2 does not work
async function test2(){
gun.get("test2").get("people").set({name: "Mark"})
await delay(2); // added this.
gun.get("test2").get("people").map(user => {
console.log("MAP DEBUG 2", user); return user
}).once((user, id) => console.log(id, user))};
} Any insight into this would be greatly appreciated. |
Hi,
tested some
map()
filters as shown in documentation here: https://gun.eco/docs/API#-a-name-map-a-gun-map-callback-Test data
Filtering "once" without a gun listener seems to work fine with single object of user "Mark".
Output:
Same with debugging output and return the "user" object in map callback
Output:
Problem 1
If I remove the first
once
beforemap([cb])
the secondonce
or alsoon
callback isn't triggered anymore?Example output
Expected output
Problem 2:
Execute following code multipe times more and more listeners added!
First time result of
once
is as expected. MAP DEBUG output twice...Second time of execution same result of
once
, but increased MAP DEBUG output?Third time...
And with each execution the MAP CALLBACK is triggered two times more... Looks like
map(cb)
adds Gun listener for each execution?Result of
once
is still the same / ok.Problem 3:
With
once().map([cb]).on(cb)
the "on() callback" is triggered twice compared to "once()"?Output:
Same with
once().map().once(cb)
works as expected with one output for each object.Maybe not related to
map(cb)
topic and just once / on... I'm not sureThe text was updated successfully, but these errors were encountered: