Skip to content

Instantly share code, notes, and snippets.

@terodox
terodox / cancellable-retry.ts
Created February 6, 2021 15:16
(Untested) A class to execute an async function with logic based retry at a specific interval
export class CancellableRetry {
private _activePromiseRejectFunction: Function;
private _functionToInvoke: Function;
private _isCancelled = false;
private _timerId: number;
private _retryInMs: number;
private _shouldRetry: (thrownError: Error) => boolean;
constructor({ functionToInvoke, shouldRetry, retryInMs }) {
this._functionToInvoke = functionToInvoke;
@terodox
terodox / tempalte-element.js
Created September 14, 2019 23:34
How to use a template element with a custom element
const helloWorldTemplate = document.createElement('template');
helloWorldTemplate.innerHTML = `<h1>Hello World!</h1>`;
document.appendChild(helloWorldTemplate);
class HelloWorld extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
const templateCopy = document.importNode(helloWorldTemplate, true);
this.shadowRoot.appendChild(templateCopy);
@terodox
terodox / attach-shadow.js
Created September 14, 2019 23:29
Attaching the shadow DOM in a custom element.
class HelloWorld extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
}
@terodox
terodox / simplest-custom-element.html
Created September 14, 2019 23:28
The html for our simplest custom element.
<hello-world></hello-world>
@terodox
terodox / registering-a-web-component.js
Created September 14, 2019 23:27
Registering a custom element.
window.customElements.define('hello-word', HelloWorld)
@terodox
terodox / simplest-web-component.js
Created September 14, 2019 23:24
The simplest web component
class HelloWorld extends HTMLElement {}