Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Motel<A>

This is your main API entry point to this library.

An instance of this class manages your vacancy observers, including methods for adding observers and listening on a DOM element. Typically the instance would be created at application startup time and would last for the duration of the app.

Internally, it creates a MutationObserver which does the actual work of detecting vacancies.

For convenience, methods on this class are chainable, allowing patterns like this:

const vacancies = Motel.create()
  .observe(...observer callback...)
  .observe(...observer callback...)
  .observe(...observer callback...)
  .subscribe(action => store.dipatch(action))
  .connect(document.querySelector('#root'));

...however note that it may be better to break these calls across different modules.

Type parameters

  • A

    The output type of this Motel instance. That is, the type of object you'll dispatch from your observer callbacks. For example, in a Redux app this would probably be your Redux action type.

Index

Methods

connect

  • connect(root: Element): Motel<A>
  • Connect a MutationObserver to the given root DOM element and begin watchng for vacancies. It also synchronously finds pre-existing vacancies in the root's subtree and reports them to observers. Observers should thus be attached before calling this method, or some vacancies may go undetected. This is especially relevant if you're using SSR.

    Parameters

    • root: Element

      Vacancies occurring on or anywhere below this element will be observed.

    Returns Motel<A>

disconnect

observe

  • Create a wildcard observer that sees every vacancy.

    Parameters

    • wildcard: "*"

      The special "*" string, which represents a pattern that matches everything.

    • handler: WildcardCallback<A>

      A callback function that runs whenever a vacancy is found.

    Returns Motel<A>

  • Create an observer that matches vacancies based on the given string pattern. Pattern matching follows the rules of a UrlPattern object.

    Parameters

    • stringPattern: string

      A pattern string as described here.

    • handler: PatternCallback<A>

      A callback function that runs whenever a vacancy is found.

    Returns Motel<A>

  • Create an observer that matches vacancies based on a regex.

    Parameters

    • regex: RegExp

      A pattern string as described here.

    • handler: RegExpCallback<A>

      A callback function that runs whenever a vacancy is found.

    Returns Motel<A>

subscribe

  • Subscribe to the output of this instance. That is, a stream of objects of type <A>. Every dispatched object will be seen by the subscriber.

    Parameters

    • subscriber: Dispatcher<A>

      A callback function which receives objects of type A dispatched from your vacancy observers.

    Returns Motel<A>

Static create

  • Create a new instance with the given options.

    typeparam

    The type of object that you'll dispatch to your app from your vacancy observers.

    Type parameters

    • AA

    Parameters

    Returns Motel<AA>

Generated using TypeDoc