Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

feat(statusTile): Display status bar tile only if active file matches one of the scopes in settings #200

Merged
merged 4 commits into from
Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dist/statusTile/updateStatusTileScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ var _require2 = require('../atomInterface'),
getAllScopes = _require2.getAllScopes;

var updateStatusTileScope = function updateStatusTileScope(element, editor) {
if (element) {
// The editor can be undefined if there is no active editor (e.g. closed all tabs).
// eslint-disable-next-line no-param-reassign
element.dataset.prettierMatchScope = editor !== undefined && getAllScopes().includes(getCurrentScope(editor)) ? 'true' : 'false';
}
if (!element) return;

// The editor can be undefined if there is no active editor (e.g. closed all tabs).
// eslint-disable-next-line no-param-reassign
element.dataset.prettierMatchScope = editor !== undefined && getAllScopes().includes(getCurrentScope(editor)) ? 'true' : 'false';
};

module.exports = updateStatusTileScope;
16 changes: 8 additions & 8 deletions src/statusTile/updateStatusTileScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const { getCurrentScope } = require('../editorInterface');
const { getAllScopes } = require('../atomInterface');

const updateStatusTileScope = (element: HTMLElement, editor: TextEditor) => {
if (element) {
// The editor can be undefined if there is no active editor (e.g. closed all tabs).
// eslint-disable-next-line no-param-reassign
element.dataset.prettierMatchScope = editor !== undefined &&
getAllScopes().includes(getCurrentScope(editor))
? 'true'
: 'false';
}
if (!element) return;

// The editor can be undefined if there is no active editor (e.g. closed all tabs).
// eslint-disable-next-line no-param-reassign
element.dataset.prettierMatchScope = editor !== undefined &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darahak What's the practical difference between returning undefined and returning 'false' here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set display: none in the statusTile stylesheet if this attribute is set to "false", so it would not work if we returned undefined.
I'm not sure I understood correctly though, does that answer your question?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, yeah.

I was thinking, if the editor can potentially be undefined here, we need to use a maybe type in the flow annotation (e.g.,?TextEditor) to indicate this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll change that.

getAllScopes().includes(getCurrentScope(editor))
? 'true'
: 'false';
};

module.exports = updateStatusTileScope;
4 changes: 4 additions & 0 deletions src/statusTile/updateStatusTileScope.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ beforeEach(() => {

it('sets the match-scope data attribute to true if the editor is in scope', () => {
getCurrentScope.mockImplementation(() => 'source.js');

const { div } = callUpdateStatusTileScope();

expect(div.dataset.prettierMatchScope).toBe('true');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we separate the "given, when, then" parts of the test with blank lines, just for readability?

});

it('sets the match-scope data attribute to false if the editor is out of scope', () => {
getCurrentScope.mockImplementation(() => 'source.html');

const { div } = callUpdateStatusTileScope();

expect(div.dataset.prettierMatchScope).toBe('false');
});