Skip to content

Commit 2321904

Browse files
authored
Merge pull request #246 from SgLy/fix-adapter-intersection-observer-margins-optional
fix(miniprogram-adapter): fields in IntersectionObserverMargins should be optional
2 parents 43f8d1a + 61dc4c0 commit 2321904

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

glass-easel-miniprogram-adapter/src/intersection.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import type * as glassEasel from 'glass-easel'
22
import { type GeneralComponent } from './component'
33

44
export type IntersectionObserverMargins = {
5-
left: number
6-
top: number
7-
right: number
8-
bottom: number
5+
left?: number
6+
top?: number
7+
right?: number
8+
bottom?: number
99
}
1010

11+
const normalizeMarginRect = (margins: IntersectionObserverMargins) => ({
12+
left: margins.left || 0,
13+
top: margins.top || 0,
14+
right: margins.right || 0,
15+
bottom: margins.bottom || 0,
16+
})
17+
1118
const defaultMargins = {
1219
left: 0,
1320
top: 0,
@@ -81,7 +88,7 @@ export class IntersectionObserver {
8188
if (!this._$margins) {
8289
throw new Error('`relativeTo` or `relativeToViewport` should be called before observe')
8390
}
84-
const { left, top, right, bottom } = this._$margins
91+
const { left, top, right, bottom } = normalizeMarginRect(this._$margins)
8592
const margin = `${top}px ${right}px ${bottom}px ${left}px`
8693
targets.forEach((target) => {
8794
let initial: number | null = this._$initialRatio

0 commit comments

Comments
 (0)