filipedeschamps / rss-feed-emitter

Super RSS News Feed aggregator written in Node.js and ES6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incrementing the emit messages

Hardik-G1 opened this issue · comments

function updates(msg, url) {
    feeder.add({
        url: url,
        eventName: 'nintendo'
    });

    feeder.on('nintendo', function(item) {
        msg.channel.send(item.link)
    })
}

when this function is called for any link it gives the required data one time but after that it is called for another link it gives the same data twice when called third time gives the same data thrice and so on... how do i fix it
updates(msg,1.com) gives a.com
updates(msg,2.com) gives b.com b.com
updates(msg,3.com) gives c.com c.com c.com

Sorry i got the error it is just the event name that is adding on, but how can i get the list of just of eventName or just the list of url so to check if that it already exist then don't start a new one.

need a feed.remove(eventName)

commented

Sorry, I'm not entirely sure I follow what you're asking.

You can get the feed list from feeder#list, and you can remove them with feeder.remove(url). If you add multiple with the same event name, its up to you to handle them....

Sorry, I'm not entirely sure I follow what you're asking.

You can get the feed list from feeder#list, and you can remove them with feeder.remove(url). If you add multiple with the same event name, its up to you to handle them....

i am asking is there way instead of url in feed.remove it can take event name to remove the event

commented

Why can't you just remove with the url?

i am creating two feed events with different name one for the whole community and one for DMs but if i want to remove with link both will be removed

commented

sooo, why can't you send to both during the event from the main url?

using the same url multiple times will cause multiple events to fire, which will bog down your system (cause it's more event listeners... more event listeners for processing the same event multiple times can cause issues if you're doing it with a lot).

My recommendation is having one event fire, and if it has some component you want sent to both dm and not dm, you're better off having the on-item handler send off both messages

sir that's the problem the DM one is optional it's up to the user that he wants feed in his/her DM. plus defining the boolean status to every user in a server of 200 people in discord will take space
one more thing if i remove the feed from feeder.list then it would not run right ?

commented

if you remove all instances. we don't enforce there being only one for a url (might change that soon), given that we only remove one instance of the same url at a time.

if (feeder.list) {
            if (feeder.list[i].eventName === x) {
                clearInterval(feeder.list[i].interval);
                delete feeder.list[i].interval;
                feeder.list.splice(i,1);
            }
        }

would this work

commented

no, you shouldn't ever remove items while looping over them, it causes... bad things.

so how should i do it?

found=0
for (let i = 0; i < feeder.list.length; i++) {
        if (feeder.list) {
            if (feeder.list[i].eventName === x) {
                found=i
            }
        }
    }
clearInterval(feeder.list[found].interval);
delete feeder.list[found].interval;
feeder.list.splice(found,1);

will this work

commented
  1. break when you find a result or keep an array of results
  2. you need to just clear the interval, deleting it is redundant

otherwise it's probably fine, but if you want to submit a pr, you'll need to write tests

please look i have first clearInterval then deleted it in the above code

commented

again, you don't need to delete it because when you splice the object off of the array, it becomes dereferenced and will be garbage collected.

image
please then fix it in src/Feed

commented

no? cause this is different. clearing and deleting alone is not the same as clearing then dereferencing the whole thing from the array.

more explanation:
destroy is used to stop it from updating, but doesn't delete all of the feed items that have been added.
if you want to use #destroy instead of manually clearing, that would be preferable.

however, destroy does not remove the feed from the array, and since you're splicing but not retaining the spliced object, the feed that was removed doesn't need other manual destruction (deleting the interval manually), because the feed would not be reused.

after a #destroy call, the feed is still ready to, for example, be added back into the feeder with the existing items that have been retrieved already.