whenAttribute

Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.dom.when

Resolve a promise when the wanted attribute on the passed HTMLElement exist or pass the check function provided

Params

  1. $elm*-HTMLElement

    The HTMLElement on which to monitor the property

  2. attribute*-String

    The attribute to monitor

  3. checkFnnullFunction

    Optional function to check the attribute. The promise is resolved when this function return true

Return

  1. -(Promise)

    The promise that will be resolved when the attribute exist on the element (and that it passes the checkFn)

Example

import { whenAttribute } from '@blackbyte/sugar/dom'

// using promise
whenAttribute($myCoolHTMLElement, 'value').then(value => {
  // do something...
});

// with a check function
whenAttribute($myCoolHTMLElement, 'value', {
  check(newVal, oldVal) {
   // make sure the value is a number
   return typeof(newVal) === 'number';
  }
}).then(value => {
  // do something...
});

Todo

  • testsnormal