Coffeekraken.io 0.0.1

whenAttribute

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

Name Type Description Status Default
elm { HTMLElement } The HTMLElement on which to monitor the property required
attribute { String } The attribute to monitor required
checkFn { Function } An optional function to check the attribute. The promise is resolved when this function return true optional null

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

Example

    import whenAttribute from 'sugarcss/js/dom/whenAttribute'
whenAttribute(myCoolHTMLElement, 'value').then((value) => {
        // the value attribute exist on the element
});
// with a checkFn
whenAttribute(myCoolHTMLElement, 'value', (newVal, oldVal) => {
        // make sure the value is a number
        return typeof(newVal) === 'number';
}).then((value) => {
        // do something with your number value...
});

Author : Olivier Bossel olivier.bossel@gmail.com