Problem with save event activate state


#1

I want to create a new package that can trigger the function each time when user save ctrl + s so I created this new package from Generate Package script.

And there In activate(state) my lib/my-package.js file I added save event to the subscription like this…

// Register command that toggles this view
this.subscriptions.add(atom.commands.add('atom-workspace', {
  'my-package:toggle': () => this.toggle()
}));

// Event save
this.subscriptions.add(atom.workspace.observeTextEditors((editor) => editor.onDidSave(this.toggle)))

In my toggle function I only have this atom.notifications.addSuccess("pycodestyle success") and so far I can activate this using ctrl + alt + o and after that I can do the ctrl + s to display the notification. Everything working fine until I removed the notification with this.modelPanel

activate(state) {
    ...
    this.modalPanel = atom.workspace.addBottomPanel({
      item: this.pycodestyleAtomView.getElement(),
      visible: false
    });
    ...
}

Now the behaviour is after activating the my-package with ctrl + alt + o then if I issue the command ctrl + s it throws error Uncaught TypeError: Cannot read property 'isVisible' of undefined

Please help me here with this error also what is the procedure for activating my-package on load ?


#3

Actually I written the code wrongly. This is the correct way to listen for changes…

 this.subscriptions.add(atom.commands.add('atom-workspace', {'core:save': () => this.toggle() }));