-
Notifications
You must be signed in to change notification settings - Fork 7.6k
add current and previous documents to currentDocumentChange event #7509
Conversation
_currentDocument = doc; | ||
$(exports).triggerHandler("currentDocumentChange"); | ||
$(exports).triggerHandler("currentDocumentChange", [_currentDocument, previousDocument]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use an associative array?
I'd take {current: _currentDocument, previous: previousDocument}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggerHandler
gets arguments in an array and then spreads them to the callback like this:
https://github.com/zaggino/brackets-git/blob/43d62647ca8d8747f1cc649019f08bc451440fcf/src/BracketsEvents.js#L51-L56
+1 for this. I actually wish every Change event we have provided a newState and an oldState. Would save on maintaining cached states. |
@zaggino This looks good -- but please just update the docs at the top of the module to indicate the new 2nd & 3rd args. |
@peterflynn done |
@@ -59,7 +59,8 @@ | |||
* - documentRefreshed -- When a Document's contents have been reloaded from disk. The 2nd arg to the | |||
* listener is the Document that has been refreshed. | |||
* | |||
* - currentDocumentChange -- When the value of getCurrentDocument() changes. | |||
* - currentDocumentChange -- When the value of getCurrentDocument() changes. 1st argument to the listener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be the second and third arguments, since the first is always the event itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sry. Early morning here :) Fixed
Looks good now -- thanks! |
Add current and previous document args to currentDocumentChange event
Useful nit to avoid calling
DocumentManager.getCurrentDocument()
everytime when hooked on the event and also the only way to know what was the previous document I think.