-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3953 from hashicorp/f-ui-polling-disconnect
UI: Polling Step 3 - Close connections when tabbing away
- Loading branch information
Showing
17 changed files
with
106 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Mixin from '@ember/object/mixin'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default Mixin.create({ | ||
visibilityHandler() { | ||
assert('visibilityHandler needs to be overridden in the Component', false); | ||
}, | ||
|
||
setupDocumentVisibility: function() { | ||
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this)); | ||
document.addEventListener('visibilitychange', this.get('_visibilityHandler')); | ||
}.on('init'), | ||
|
||
removeDocumentVisibility: function() { | ||
document.removeEventListener('visibilitychange', this.get('_visibilityHandler')); | ||
}.on('willDestroy'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Mixin from '@ember/object/mixin'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default Mixin.create({ | ||
visibilityHandler() { | ||
assert('visibilityHandler needs to be overridden in the Route', false); | ||
}, | ||
|
||
setupDocumentVisibility: function() { | ||
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this)); | ||
document.addEventListener('visibilitychange', this.get('_visibilityHandler')); | ||
}.on('activate'), | ||
|
||
removeDocumentVisibility: function() { | ||
document.removeEventListener('visibilitychange', this.get('_visibilityHandler')); | ||
}.on('deactivate'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import Mixin from '@ember/object/mixin'; | ||
import { computed } from '@ember/object'; | ||
import { assert } from '@ember/debug'; | ||
import WithVisibilityDetection from './with-route-visibility-detection'; | ||
|
||
export default Mixin.create({ | ||
export default Mixin.create(WithVisibilityDetection, { | ||
watchers: computed(() => []), | ||
|
||
cancelAllWatchers() { | ||
this.get('watchers').forEach(watcher => { | ||
assert('Watchers must be Ember Concurrency Tasks.', !!watcher.cancelAll); | ||
watcher.cancelAll(); | ||
}); | ||
}, | ||
|
||
startWatchers() { | ||
assert('startWatchers needs to be overridden in the Route', false); | ||
}, | ||
|
||
setupController() { | ||
this.startWatchers(...arguments); | ||
return this._super(...arguments); | ||
}, | ||
|
||
visibilityHandler() { | ||
if (document.hidden) { | ||
this.cancelAllWatchers(); | ||
} else { | ||
this.startWatchers(this.controller, this.controller.get('model')); | ||
} | ||
}, | ||
|
||
actions: { | ||
willTransition() { | ||
this.get('watchers').forEach(watcher => { | ||
assert('Watchers must be Ember Concurrency Tasks.', !!watcher.cancelAll); | ||
watcher.cancelAll(); | ||
}); | ||
this.cancelAllWatchers(); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters