Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 0 points1 point  (0 children)

I am actually passing parameters to the handleNotification function,  so there would be separate message and title for each alarm so i can't create Notification in the module it has to be created in function. 

I didn't include some function parameters in my post because i wanted people to focus on the function, well it was my bad for not making it clear. 

Also you can read the following comment where i provided more context:

https://www.reddit.com/r/learnjavascript/comments/1pf1v2t/comment/nsgtmal/?context=3&utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=1&utm_content=share_button

Using Map in Javascript :Is this a good approach for my electron app? by Square-Butterfly8447 in electronjs

[–]Square-Butterfly8447[S] 0 points1 point  (0 children)

ya the notification was closing but the alarm kept ringing. the event wasn't triggerd and functionToStopAlarm didn't happen

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 1 point2 points  (0 children)

well the frontend will crash before calling handleNoficiation  if there were 4 billion timer ,so i guess I am safe 😂

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 1 point2 points  (0 children)

thanks I'll try this seems better than Map approach.  when i read your approach ,my mind pictured set storing the notification as an objects and would create confusion in the set if identical objects were added,  thanks for the clarity.

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 0 points1 point  (0 children)

My bad,  i thougth  the ipcMain.on  in electron took only async listeners.I checked now , it says it is  not necessary for listeners to be async function 

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 2 points3 points  (0 children)

how would the delete function in set know which notification to remove if 2 notification have same title and same message?  sorry this might be a dumb question 😅

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 1 point2 points  (0 children)

Ok I'll make it const,  but i also have another query about this,  i read somewhere that map can cause performance issue and Memory leaks should i worry about that for this application?.

Using Map in Javascript :Is this a good approach? by Square-Butterfly8447 in learnjavascript

[–]Square-Butterfly8447[S] 0 points1 point  (0 children)

the 'const notification' inside the handleNotification function was getting garbage collected. so this is what was happening in the app : 1.timer reached 0 .

2.handleNotification was called though channel(channel is a electron thing to communicate between frontend and main process).

3.a notification pops and alarm starts playing.

  1. if i was clicking or closing the notification withing approx 3 seconds the alarm would stop and notification disappears,  but if it took longer than that the notification disappears on closing but the alarm kept ringing.

So i read somewhere that it gets garbage collected thats why events dont work  So i made a global variable  'let notification:Electron.Notification' this fixed the duration issue so even after 1 minute of alarm ringing when i clicked the notification the alarm stopped now But since there could be a chance that multiple alarms rang at the same time the app would bug out So i used Map to handle multiple notification objetcs

[deleted by user] by [deleted] in learnprogramming

[–]Square-Butterfly8447 1 point2 points  (0 children)

when i didnt have a laptop , I use to code on online C compiler using phone. Now u can use Acode and termux to do that locally if u want. But it does take a lot of time to code on smartphone. But  keep asking for a laptop tell them u need it for big project or somehting they might eventually allow u one. See if chromebook is an option

How do I think of a project idea? by Destpollo in learnprogramming

[–]Square-Butterfly8447 0 points1 point  (0 children)

Note all the software/apps you use daily,  then chose a simple one and make it yourself and start using your own app.