Emit event between a view and status-bar


#1

Im making a package that use the status-bar and a view with a input that execute a child process but im having a problem to emit an event to update the status-bar. Actually i don’t know how emit an event in this case.

some ideas to do this.


#2

Check the event-kit package for the infrastructure and basic documentation of how Atom does it. You can use event-kit in your own packages too.


#3

thanks that was useful. sorry is this will be a noob question but how i can debug my package because i see in time cop that my package take 157ms to load i want to know if i can get better performance.

my package is simple he execute a child process to stop or start mac native server.
when atom start the package will check if the server is running and add to status bar a tile showing if the server is running. when i execute a command in the plugin this stop the server and update the status bar with the event-kit.


#4

Can I see your code? Is it on github?


#5

is here:

thanks


#6

The code in your main file is excellent. It defers everything until activation. However, your package.json says to activate immediately when Atom loads. This is because it has no activation event specified. So the code to defer things doesn’t help since it activates immediately anyway.

Try adding activationEvents to your package.json and see how much faster it is.


#7

Where i can find info about activationEvents in atom?


#8

activationCommands is an optional property of package.json.

"activationCommands (Optional): an Array of Strings identifying commands that trigger your package’s activation. You can delay the loading of your package until one of these events is triggered".

From https://atom.io/docs/v0.184.0/creating-a-package


#9

oh is that sorry xD thanks for all ur help.

u know if exist a list of events for atom when this is loaded because in my case i need my extension running in the start to know is my server is running or not.


#10

In that case just don’t put in any activation event and it will start right away. You will not be able to start any faster but 157 ms is not bad.


#11

well then is ok thanks for ur help :smile:


#12

Hey @mark_hahn and @leedohm see this:

when i use this:

{View, $, $$} = require ‘atom’

make that the package load in less seconds than this

{View, $, $$} = require ‘atom-space-pen-views’

with this last i get over 100 ms to load a package but with the first i get between 10 ~ 20 ms.

In the guide to upgrade a package they recommend to use the second approach but the results in time cop let me confuse.


#13

This does nothing. Those aren’t properties of atom. Even if you had some real properties atom would still be much faster because it just has object properties. atom-space-pen-views is a complex module than runs a lot of code.


#14

I understand that but when u creating package and see that difference what is the best way to go.

the two approach are working but for atom what is the best to do?

In future the first approach will don’t work or something?


#15

Yes, but I don’t know how long it will take. I’m surprised it works at all.

Anyway, my comment about it being faster because it is just a simple object holds.


#16

Check the Deprecation Cop view. Requiring those values from atom is deprecated and will be removed at some point, almost certainly before v1.0. So if you want your code to continue working, you should update it.


#17

Yes i do that, only im worry about the performance when i see that the load time has a impact pulling from 10~20 ms to 150ms i think something is wrong.

Sometimes i only need use a View component and if i follow the upgrade package guide i understand that now i have to use atom-space-pen-views if i need use a View.

i know that using atom-space-pen-views will increase the size of my package because he not only have a view, he have more components inside and like mark_hahn say is a complex code that runs a lot of code.

Actually for packages that load a component from atom-space-pen-views in the activation method get above 70~100ms to load in time cop.

I experiment that updating some packages, im trying to follow all the specifications in the upgrade packages guide to make all work right and in the same time im thinking in the performance, Using atom-space-pen-views and worried about the load time. i start to separate all the view from the logic and using the event-kit to only create the view when is really necessary that get less load time from 140~150ms to 40~50ms


#18

As you can see here, if you’re just using the View, you can also do {View} = require 'space-pen' so the ScrollView and friends don’t get initialized.


#19

I see that package before (space-pen) but in the upgrade guide talk about use atom-space-pen-views for view too maybe i understand badly. that option will be available in future (space-pen)?


#20

If I’m correct, space-pen is just a view framework, whereas atom-space-pen-views is a package that provides some views specifically for Atom. But as you can see in the link I provided above, require('atom-space-pen-views').View === require('space-pen').View, so if View is the only thing you’ll be using you should be fine using either one