diff options
author | Denys Mishunov <dmishunov@gitlab.com> | 2019-06-03 16:28:52 +0200 |
---|---|---|
committer | Denys Mishunov <dmishunov@gitlab.com> | 2019-06-03 16:28:52 +0200 |
commit | 19c900c4265b6ba604ffe0e2ff0cfa01ed686a10 (patch) | |
tree | 008af8dfee49a060f4583be64aec43171304074b | |
parent | 33265ea368d2af255d6289eaf764c9724269397e (diff) | |
download | gitlab-ce-denys-experiement-intersectionobserver-diffs.tar.gz |
Sketched potential usage for IntrsectionOberverdenys-experiement-intersectionobserver-diffs
-rw-r--r-- | app/assets/javascripts/diffs/components/app.vue | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index 11d6672cacf..9565c77fa87 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -23,6 +23,8 @@ import { CENTERED_LIMITED_CONTAINER_CLASSES, } from '../constants'; +const isLeaving = {}; + export default { name: 'DiffsApp', components: { @@ -177,6 +179,33 @@ export default { 'scrollToFile', 'toggleShowTreeList', ]), + setIntersectionObserver() { + const config = { + root: null, // avoiding 'root' or setting it to 'null' sets it to default value: viewport + rootMargin: '-25% 0px -50% 0px', + threshold: 0.1, + }; + const observer = new IntersectionObserver(entries => { + entries.forEach(entry => { + if (entry.isIntersecting) { + // we are ENTERING the "capturing frame". Mark file as `active` + isLeaving[entry.target.id] = true; + // Do something with ENTERING entry + console.log(`${entry.target.id} is ENTERING the frame`); + } else if (isLeaving[entry.target.id]) { + // we are EXITING the "capturing frame". Mark file as `read` + isLeaving[entry.target.id] = false; + console.log(`${entry.target.id} is LEAVING the frame`); + // Do something with LEAVING entry + } + }); + }, config); + + const diffs = document.querySelectorAll('.diff-files-holder .diff-file'); + diffs.forEach(diff => { + observer.observe(diff); + }); + }, refetchDiffData() { this.assignedDiscussions = false; this.fetchData(false); @@ -192,6 +221,7 @@ export default { () => { this.setDiscussions(); this.startRenderDiffsQueue(); + this.setIntersectionObserver(); }, { timeout: 1000 }, ); |