How to access to the notification when onDidClick happens


#1

I read the related topics and I tried to use notification inside the onDidClick function but it throws an error saying that notification is not defined.

I tried to read the documentation but it says that the NotificationManager returns a NotificationElement and the link returns a 404. Probable it should redirect to Notification?


#2

The NotificationManager API can be accessed through atom.notifications.

Where did you find the dead link?


#3

Yup, I know I can access it with atom.notifications but I was looking for any other alternative without iterating the loop. Someting like this:

...
buttons: [
  {
     text: 'OK',
     onDidClick: () => {
       this.close()
     }
  }
]

The broken links can be found in NotificationManager API on the adding notification methods on onDidClick description.


#4

Do you just want to be able to click a button to dismiss it? Because the notifications will do that on their own if options.dismissable is true.


#5

But I want to perform an action when clicking the Cancel button and it should close the notification.


#6

And what code are you using to make this happen?


#7

Assign the notification to a variable, you can then dismiss()it.

Example:

notification = atom.notifications.addSuccess(
  "Close this notification",
  dismissable: true,
  buttons: [
    {
      text: "Close"
      onDidClick: ->
        notification.dismiss()
    }
  ]
)

#8

@DamnedScholar The code I have is like the example shown by @idleberg.

Assigning the notification a variable worked. Thanks!