Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass watchedNodes to Watcher/WatcherAdapter #403

Merged
merged 6 commits into from
May 20, 2019
Merged

Conversation

oligriffiths
Copy link
Contributor

@oligriffiths oligriffiths commented May 18, 2019

The intention of this PR is to make the watchedNodes an argument to the constructor of the watcher, as they're a required dependency and watcher can't work without them.
Additionally, NOT reaching into the builder to get them will help with the ember CLI integration of the watcher.

@thoov
Copy link
Member

thoov commented May 18, 2019

@oligriffiths Should this be apart of the 3.0 release or should it come after?

@oligriffiths
Copy link
Contributor Author

@thoov I’d prefer if it were but I’m not going to be able to work much more on it until Monday

@lifeart
Copy link
Contributor

lifeart commented May 18, 2019

Just wondering, if it's a have sence - use current git revision for trigger rebuild if it changes (for upstream changes) or use requests from IDE like VSCode language server to get exact changed files (without watching overhead)

@oligriffiths
Copy link
Contributor Author

@lifesrt the fit revision doesn’t know about changed files, only committed ones. Not sure how this would help?

@thoov
Copy link
Member

thoov commented May 18, 2019

@oligriffiths This looks good. Just to confirm that this is so we dont have to do this? (https://github.com/ember-cli/ember-cli/pull/8614/files#diff-9ff56008b40607a31bc04df7f41906cbR45)

test/watcher_adapter_test.js Outdated Show resolved Hide resolved
@oligriffiths
Copy link
Contributor Author

@thoov correct. Also, the things to watch (nodes) are a direct dependency of this class. To me it makes more sense for them to be a mandatory argument rather than reaching in to the builder to get them

@@ -199,7 +202,7 @@ describe('Watcher', function() {

it('does nothing if already quitting', function() {
const adapterQuit = sinon.spy(adapter, 'quit');
const watcher = new Watcher(builder, { watcherAdapter: adapter });
const watcher = new Watcher(builder, [watchedNodeBasic], { watcherAdapter: adapter });
watcher._quittingPromise = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

using private API in tests is an anti pattern, let's try and use public API's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

@stefanpenner
Copy link
Contributor

stefanpenner commented May 20, 2019

@lifeart I think asking git, for what is different, isn't a bad idea. We should explore that sometime. That being said, without polling git, I don't think git can notify us of a change.

* ensure new watchedNodes are passed to the watchAdapter
* remove some mocks/stubs (we should try and remove the rest at some point) as they break encapsulation
* Separate serve from it’s implementation, Server can now be tested independently of mocking `process` (fixed flakey test)
* fix some mocks/spys now that internal implementation have changed (TODO: we need to remove many of these mocks/spys)
* fix race condition in dummy watcher
* fix lib/cli’s server actionPromise, which had code in it to support a broken mock
@oligriffiths oligriffiths changed the title [WIP] Pass watchedNodes to Watcher/WatcherAdapter Pass watchedNodes to Watcher/WatcherAdapter May 20, 2019
@thoov thoov self-requested a review May 20, 2019 17:56
@stefanpenner stefanpenner merged commit 41310dd into master May 20, 2019
@stefanpenner stefanpenner deleted the watcher-constructor branch May 20, 2019 17:58
@@ -10,28 +10,30 @@ const logger = require('heimdalljs-logger')('broccoli:watcher');
// principle.

module.exports = class Watcher extends EventEmitter {
constructor(builder, options) {
constructor(builder, watchedNodes = [], options = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

If the watched nodes are required, why do we default them?

if (this.options.debounce == null) {
this.options.debounce = 100;
}
this.builder = builder;
this.watcherAdapter =
this.options.watcherAdapter || new WatcherAdapter(this.options.saneOptions);
this.options.watcherAdapter ||
new WatcherAdapter(watchedNodes || [], this.options.saneOptions);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we default watchedNodes twice?

@@ -18,20 +19,29 @@ function bindFileEvent(adapter, watcher, node, event) {
}

module.exports = class WatcherAdapter extends EventEmitter {
constructor(options) {
constructor(watchedNodes = [], options) {
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, we should just require an arg here. This defaulting is a bit odd (e.g. it only supports new WatcherAdapter(undefined, { /* options here */ })).

@@ -591,18 +595,22 @@ describe('cli', function() {
});
});

// TODO: remove these mocks and spys
Copy link
Member

Choose a reason for hiding this comment

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

Can we file an issue to keep track of this?

@oligriffiths
Copy link
Contributor Author

@rwjblue valid points, will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants