Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable API #23

Open
kettanaito opened this issue Dec 18, 2018 · 0 comments
Open

Stable API #23

kettanaito opened this issue Dec 18, 2018 · 0 comments

Comments

@kettanaito
Copy link
Owner

kettanaito commented Dec 18, 2018

I suggest to introduce a stable API for the next major version 1.0.

Motivation

  • Easier, intuitive usage
  • Smaller internals due to efficient API setup
  • Export some internal functions

API

  • takeSnapshot(element: HTMLElement | HTMLCollection, options: SnapshotOptions): SnapshotResult

  • observe({ bounds?: SnapshotBounds, snapshots?: SnapshotOptions[] }): ObserverEventHandlers

Usage

Basic usage

import { observe } from 'sentinel-dom'

const observer = observe({
  elements: document.getElementById('box')
})

observer.on('visible', (element) => {})
observer.once('visible', (element) => {})

Custom snapshots

import { observe } from 'sentinel-dom'

const observer = observe({
  elements: document.getElementsByClassName('target'),
  snapshots: {
    partiallyVisible: {
      thresholdY: 50,
    }
  }
})

observer.once('partiallyVisible', (element) => {})
observer.on('visible', (element) => {}) // default snapshots still available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant