Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to abstract away the usage of browser's window object?

How would one abstract away the usage of browser's window object when using the Aurelia framework? I would like to avoid direct dependency on the browser when using functionality such as setInterval or addEventListener for example.

Aurelia has something called Platform Abstraction Library which in theory should provide the functionality I am looking for. However, I could not find any documentation about it at the time of writing this question.

like image 352
Jaanus Varus Avatar asked Jan 17 '16 18:01

Jaanus Varus


1 Answers

Few examples:

import {DOM, PLATFORM, FEATURE} from 'aurelia-pal';

PLATFORM.addEventListener('click', e => ...);
PLATFORM.requestAnimationFrame(() => ...);

let event = DOM.createCustomEvent('foo', { bubbles: true });
DOM.dispatchEvent(event);
let element = DOM.createElement('div');

if (FEATURE.shadowDOM && FEATURE.scopedCSS && FEATURE.htmlTemplateElement) {
  ...
}

There's no setTimeout / setInterval in the PAL- I think because aurelia doesn't use setTimeout. I've added an issue to get these added.

like image 72
Jeremy Danyow Avatar answered Nov 09 '22 23:11

Jeremy Danyow