Skip to content

Commit 3e67bbb

Browse files
committed
Clean up index.ts
Move functions in index.ts into utils.ts
1 parent 3042aa5 commit 3e67bbb

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/index.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ distributed under the License is distributed on an "AS IS" BASIS,
99
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
*/
1111

12-
import { SpanielIntersectionObserver, generateEntry } from './intersection-observer';
12+
import { SpanielIntersectionObserver } from './intersection-observer';
1313

14-
import { SpanielTrackedElement, DOMMargin, IntersectionObserverClass } from './interfaces';
14+
import { SpanielTrackedElement, IntersectionObserverClass } from './interfaces';
1515

1616
export { Watcher, WatcherConfig } from './watcher';
1717

1818
import { SpanielObserver } from './spaniel-observer';
1919

2020
import { setGlobalEngine, getGlobalEngine } from './metal/engine';
2121

22-
import { getGlobalScheduler, on, off, scheduleWork, scheduleRead, Frame } from './metal/index';
22+
import { on, off, scheduleWork, scheduleRead } from './metal/index';
2323

2424
import w from './metal/window-proxy';
2525

@@ -38,19 +38,3 @@ export {
3838
setGlobalEngine,
3939
getGlobalEngine
4040
};
41-
42-
export function queryElement(el: Element, callback: (bcr: ClientRect, frame: Frame) => void) {
43-
getGlobalScheduler().queryElement(el, callback);
44-
}
45-
46-
export function elementSatisfiesRatio(
47-
el: HTMLElement,
48-
ratio: number = 0,
49-
callback: (result: Boolean) => void,
50-
rootMargin: DOMMargin = { top: 0, bottom: 0, left: 0, right: 0 }
51-
) {
52-
queryElement(el, (bcr: ClientRect, frame: Frame) => {
53-
let entry = generateEntry(frame, bcr, el, rootMargin);
54-
callback(entry.isIntersecting && entry.intersectionRatio >= ratio);
55-
});
56-
}

src/utils.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
import { generateEntry } from './intersection-observer';
2+
3+
import { DOMMargin } from './interfaces';
4+
5+
export { Watcher, WatcherConfig } from './watcher';
6+
7+
import { getGlobalScheduler, Frame } from './metal/index';
8+
19
export function calculateIsIntersecting({ intersectionRect }: { intersectionRect: ClientRect }) {
210
return intersectionRect.width > 0 || intersectionRect.height > 0;
311
}
12+
13+
export function queryElement(el: Element, callback: (bcr: ClientRect, frame: Frame) => void) {
14+
getGlobalScheduler().queryElement(el, callback);
15+
}
16+
17+
export function elementSatisfiesRatio(
18+
el: HTMLElement,
19+
ratio: number = 0,
20+
callback: (result: Boolean) => void,
21+
rootMargin: DOMMargin = { top: 0, bottom: 0, left: 0, right: 0 }
22+
) {
23+
queryElement(el, (bcr: ClientRect, frame: Frame) => {
24+
let entry = generateEntry(frame, bcr, el, rootMargin);
25+
callback(entry.isIntersecting && entry.intersectionRatio >= ratio);
26+
});
27+
}

0 commit comments

Comments
 (0)