File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 11fs = require ' fs'
2+
3+ {Emitter } = require ' emissary'
4+
25jsSHA = require ' jssha'
36{chomp } = require ' line-chomper'
47traceParser = null
@@ -12,6 +15,9 @@ ACTIVE = null
1215#
1316class Stacktrace
1417
18+ # Turn the Stacktrace class into an emitter.
19+ Emitter .extend this
20+
1521 constructor : (@frames = [], @message = ' ' ) ->
1622
1723 # Internal: Compute the SHA256 checksum of the normalized stacktrace.
@@ -45,11 +51,18 @@ class Stacktrace
4551 # Public: Mark this trace as the "active" one. The active trace is shown in the navigation view
4652 # and its frames are given a marker in an open {EditorView}.
4753 #
48- activate : -> ACTIVE = this
54+ activate : ->
55+ former = ACTIVE
56+ ACTIVE = this
57+ if former isnt ACTIVE
58+ Stacktrace .emit ' active-changed' , oldTrace : former, newTrace : ACTIVE
4959
5060 # Public: Deactivate this trace if it's active.
5161 #
52- deactivate : -> ACTIVE = null if ACTIVE is this
62+ deactivate : ->
63+ if ACTIVE is this
64+ ACTIVE = null
65+ Stacktrace .emit ' active-changed' , oldTrace : this , newTrace : null
5366
5467 # Public: Parse zero to many Stacktrace instances from a corpus of text.
5568 #
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ describe 'Stacktrace', ->
7979 afterEach ->
8080 activated = Stacktrace .getActivated ()
8181 activated .deactivate () if activated?
82+ Stacktrace .off ' active-changed'
8283
8384 it ' can be activated' , ->
8485 trace .activate ()
@@ -93,6 +94,14 @@ describe 'Stacktrace', ->
9394 trace .deactivate ()
9495 expect (Stacktrace .getActivated ()).toBeNull ()
9596
97+ it ' broadcasts a "active-changed" event' , ->
98+ event = null
99+ Stacktrace .on ' active-changed' , (e ) -> event = e
100+
101+ trace .activate ()
102+ expect (event .oldTrace ).toBeNull ()
103+ expect (event .newTrace ).toBe (trace)
104+
96105describe ' Frame' , ->
97106 [frame ] = []
98107
You can’t perform that action at this time.
0 commit comments