MCPcopy
hub / github.com/ampproject/amphtml / patchIntersectionObserver

Function patchIntersectionObserver

build-system/common/update-packages.js:63–74  ·  view source on GitHub ↗

* Patches Intersection Observer polyfill by wrapping its body into `install` * function. * This gives us an option to control when and how the polyfill is installed. * The polyfill can only be installed on the root context.

()

Source from the content-addressed store, hash-verified

61 * The polyfill can only be installed on the root context.
62 */
63function patchIntersectionObserver() {
64 // Copies intersection-observer into a new file that has an export.
65 const patchedName =
66 'node_modules/intersection-observer/intersection-observer.install.js';
67 let file = fs
68 .readFileSync('node_modules/intersection-observer/intersection-observer.js')
69 .toString();
70
71 // Wrap the contents inside the install function.
72 file = `export function installIntersectionObserver() {\n${file}\n}\n`;
73 writeIfUpdated(patchedName, file);
74}
75
76/**
77 * Patches Resize Observer polyfill by wrapping its body into `install`

Callers 1

updatePackagesFunction · 0.85

Calls 2

writeIfUpdatedFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected