-
Notifications
You must be signed in to change notification settings - Fork 1
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 #90 from GoogleChromeLabs/video/observer
News Videos - Intersection Observer
- Loading branch information
Showing
30 changed files
with
303 additions
and
68 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
apps/news-site/news-site-next-app-router/src/hooks/use-intersection-observer.js
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,27 @@ | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function useIntersectionObserver( { callback }) { | ||
const elementRef = useRef(undefined); | ||
const intersectionObserver = useRef(undefined); | ||
|
||
useEffect( | ||
function() { | ||
const element = elementRef.current; | ||
intersectionObserver.current = new IntersectionObserver(callback); | ||
intersectionObserver.current.observe(element); | ||
|
||
return function () { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.unobserve(element); | ||
|
||
}; | ||
}, [elementRef] | ||
); | ||
|
||
function disconnect() { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.disconnect(); | ||
} | ||
|
||
return { elementRef, disconnect }; | ||
} |
24 changes: 22 additions & 2 deletions
24
apps/news-site/news-site-next-app-router/src/partials/article/article-video.jsx
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
27 changes: 27 additions & 0 deletions
27
apps/news-site/news-site-next-pages-router/src/hooks/use-intersection-observer.js
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,27 @@ | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function useIntersectionObserver( { callback }) { | ||
const elementRef = useRef(undefined); | ||
const intersectionObserver = useRef(undefined); | ||
|
||
useEffect( | ||
function() { | ||
const element = elementRef.current; | ||
intersectionObserver.current = new IntersectionObserver(callback); | ||
intersectionObserver.current.observe(element); | ||
|
||
return function () { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.unobserve(element); | ||
|
||
}; | ||
}, [elementRef] | ||
); | ||
|
||
function disconnect() { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.disconnect(); | ||
} | ||
|
||
return { elementRef, disconnect }; | ||
} |
24 changes: 22 additions & 2 deletions
24
apps/news-site/news-site-next-pages-router/src/partials/article/article-video.jsx
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 |
---|---|---|
@@ -1 +1 @@ | ||
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/ec187bc9a45ccd09.css" as="style"/><link rel="stylesheet" href="./_next/static/css/ec187bc9a45ccd09.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./workload-testing-utils.min.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./workload-test.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./_next/static/chunks/webpack-dabe763974b7e688.js" defer=""></script><script src="./_next/static/chunks/framework-2ccfc1b811a4e007.js" defer=""></script><script src="./_next/static/chunks/main-d70fd7e950e8d98d.js" defer=""></script><script src="./_next/static/chunks/pages/_app-49cdd33e11c5c280.js" defer=""></script><script src="./_next/static/chunks/pages/_error-b750ae521d56f53f.js" defer=""></script><script src="./_next/static/GVijF8IiW-oscErTe7byT/_buildManifest.js" defer=""></script><script src="./_next/static/GVijF8IiW-oscErTe7byT/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><div id="sitemap-container"></div><div id="login-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"GVijF8IiW-oscErTe7byT","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html> | ||
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/ec187bc9a45ccd09.css" as="style"/><link rel="stylesheet" href="./_next/static/css/ec187bc9a45ccd09.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./workload-testing-utils.min.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./workload-test.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./_next/static/chunks/webpack-dabe763974b7e688.js" defer=""></script><script src="./_next/static/chunks/framework-2ccfc1b811a4e007.js" defer=""></script><script src="./_next/static/chunks/main-d70fd7e950e8d98d.js" defer=""></script><script src="./_next/static/chunks/pages/_app-49cdd33e11c5c280.js" defer=""></script><script src="./_next/static/chunks/pages/_error-b750ae521d56f53f.js" defer=""></script><script src="./_next/static/wrEsXCWOzM4QfYOpj55CR/_buildManifest.js" defer=""></script><script src="./_next/static/wrEsXCWOzM4QfYOpj55CR/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><div id="sitemap-container"></div><div id="login-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"wrEsXCWOzM4QfYOpj55CR","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html> |
1 change: 0 additions & 1 deletion
1
apps/news-site/news-site-next/dist/_next/static/chunks/pages/index-79d3d7a93274c482.js.map
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ic/chunks/pages/index-79d3d7a93274c482.js → ...ic/chunks/pages/index-9ce97f331f88ffe3.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
apps/news-site/news-site-next/dist/_next/static/chunks/pages/index-9ce97f331f88ffe3.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...c/GVijF8IiW-oscErTe7byT/_buildManifest.js → ...c/wrEsXCWOzM4QfYOpj55CR/_buildManifest.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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 +1 @@ | ||
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/ec187bc9a45ccd09.css" as="style"/><link rel="stylesheet" href="./_next/static/css/ec187bc9a45ccd09.css" data-n-g=""/><link rel="preload" href="./_next/static/css/33ac65976d350a23.css" as="style"/><link rel="stylesheet" href="./_next/static/css/33ac65976d350a23.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./workload-testing-utils.min.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./workload-test.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./_next/static/chunks/webpack-dabe763974b7e688.js" defer=""></script><script src="./_next/static/chunks/framework-2ccfc1b811a4e007.js" defer=""></script><script src="./_next/static/chunks/main-d70fd7e950e8d98d.js" defer=""></script><script src="./_next/static/chunks/pages/_app-49cdd33e11c5c280.js" defer=""></script><script src="./_next/static/chunks/463e5e2b-76fd1f216b2a8cb0.js" defer=""></script><script src="./_next/static/chunks/978-f094c48b437e4ca3.js" defer=""></script><script src="./_next/static/chunks/pages/index-79d3d7a93274c482.js" defer=""></script><script src="./_next/static/GVijF8IiW-oscErTe7byT/_buildManifest.js" defer=""></script><script src="./_next/static/GVijF8IiW-oscErTe7byT/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><div id="sitemap-container"></div><div id="login-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"GVijF8IiW-oscErTe7byT","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html> | ||
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/ec187bc9a45ccd09.css" as="style"/><link rel="stylesheet" href="./_next/static/css/ec187bc9a45ccd09.css" data-n-g=""/><link rel="preload" href="./_next/static/css/33ac65976d350a23.css" as="style"/><link rel="stylesheet" href="./_next/static/css/33ac65976d350a23.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./workload-testing-utils.min.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./workload-test.js" type="module" async="" defer="" data-nscript="beforeInteractive"></script><script src="./_next/static/chunks/webpack-dabe763974b7e688.js" defer=""></script><script src="./_next/static/chunks/framework-2ccfc1b811a4e007.js" defer=""></script><script src="./_next/static/chunks/main-d70fd7e950e8d98d.js" defer=""></script><script src="./_next/static/chunks/pages/_app-49cdd33e11c5c280.js" defer=""></script><script src="./_next/static/chunks/463e5e2b-76fd1f216b2a8cb0.js" defer=""></script><script src="./_next/static/chunks/978-f094c48b437e4ca3.js" defer=""></script><script src="./_next/static/chunks/pages/index-9ce97f331f88ffe3.js" defer=""></script><script src="./_next/static/wrEsXCWOzM4QfYOpj55CR/_buildManifest.js" defer=""></script><script src="./_next/static/wrEsXCWOzM4QfYOpj55CR/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><div id="sitemap-container"></div><div id="login-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"wrEsXCWOzM4QfYOpj55CR","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html> |
27 changes: 27 additions & 0 deletions
27
apps/news-site/news-site-next/src/hooks/use-intersection-observer.js
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,27 @@ | ||
import { useRef, useEffect } from "react"; | ||
|
||
export function useIntersectionObserver( { callback }) { | ||
const elementRef = useRef(undefined); | ||
const intersectionObserver = useRef(undefined); | ||
|
||
useEffect( | ||
function() { | ||
const element = elementRef.current; | ||
intersectionObserver.current = new IntersectionObserver(callback); | ||
intersectionObserver.current.observe(element); | ||
|
||
return function () { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.unobserve(element); | ||
|
||
}; | ||
}, [elementRef] | ||
); | ||
|
||
function disconnect() { | ||
if (intersectionObserver.current) | ||
intersectionObserver.current.disconnect(); | ||
} | ||
|
||
return { elementRef, disconnect }; | ||
} |
24 changes: 22 additions & 2 deletions
24
apps/news-site/news-site-next/src/partials/article/article-video.jsx
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
29 changes: 29 additions & 0 deletions
29
apps/news-site/news-site-nuxt-pages-router/composables/use-intersection-observer.js
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,29 @@ | ||
import { ref, watch } from "vue"; | ||
|
||
export function useIntersectionObserver({ callback }) { | ||
const elementRef = ref(undefined); | ||
const intersectionObserver = ref(undefined); | ||
|
||
watch(() => elementRef, () => { | ||
if (!elementRef.value) | ||
return; | ||
|
||
const element = elementRef.value; | ||
intersectionObserver.value = new IntersectionObserver(callback); | ||
intersectionObserver.value.observe(element); | ||
|
||
// eslint-disable-next-line consistent-return | ||
return function () { | ||
if (intersectionObserver.value) | ||
intersectionObserver.value.unobserve(element); | ||
|
||
}; | ||
}, { deep: true, immediate: true }); | ||
|
||
function disconnect() { | ||
if (intersectionObserver.value) | ||
intersectionObserver.value.disconnect(); | ||
} | ||
|
||
return { elementRef, disconnect }; | ||
} |
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
29 changes: 29 additions & 0 deletions
29
apps/news-site/news-site-nuxt/composables/use-intersection-observer.js
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,29 @@ | ||
import { ref, watch } from "vue"; | ||
|
||
export function useIntersectionObserver({ callback }) { | ||
const elementRef = ref(undefined); | ||
const intersectionObserver = ref(undefined); | ||
|
||
watch(() => elementRef, () => { | ||
if (!elementRef.value) | ||
return; | ||
|
||
const element = elementRef.value; | ||
intersectionObserver.value = new IntersectionObserver(callback); | ||
intersectionObserver.value.observe(element); | ||
|
||
// eslint-disable-next-line consistent-return | ||
return function () { | ||
if (intersectionObserver.value) | ||
intersectionObserver.value.unobserve(element); | ||
|
||
}; | ||
}, { deep: true, immediate: true }); | ||
|
||
function disconnect() { | ||
if (intersectionObserver.value) | ||
intersectionObserver.value.disconnect(); | ||
} | ||
|
||
return { elementRef, disconnect }; | ||
} |
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
Oops, something went wrong.