Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit f27ff14

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(patch): fix #833, add IntersectionObserver support (#880)
1 parent b1e5970 commit f27ff14

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/browser/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
5454
}
5555
patchClass('MutationObserver');
5656
patchClass('WebKitMutationObserver');
57+
patchClass('IntersectionObserver');
5758
patchClass('FileReader');
5859
});
5960

test/browser/browser.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,24 @@ describe('Zone', function() {
21222122
}));
21232123
});
21242124

2125+
it('IntersectionObserver should run callback in zone',
2126+
ifEnvSupportsWithDone('IntersectionObserver', (done: Function) => {
2127+
const div = document.createElement('div');
2128+
const options: any = {root: div, rootMargin: '0px', threshold: 0};
2129+
2130+
const zone = Zone.current.fork({name: 'intersectionObserverZone'});
2131+
2132+
zone.run(() => {
2133+
const observer = new IntersectionObserver(() => {
2134+
expect(Zone.current.name).toEqual(zone.name);
2135+
observer.unobserve(div);
2136+
done();
2137+
}, options);
2138+
observer.observe(div);
2139+
});
2140+
document.body.appendChild(div);
2141+
}));
2142+
21252143
it('HTMLCanvasElement.toBlob should be a ZoneAware MacroTask',
21262144
ifEnvSupportsWithDone(supportCanvasTest, (done: Function) => {
21272145
const canvas = document.createElement('canvas');

0 commit comments

Comments
 (0)