Skip to content

Instantly share code, notes, and snippets.

View tomasswood's full-sized avatar

Thomas Wood tomasswood

View GitHub Profile
@tomasswood
tomasswood / setTimeoutLoop.js
Last active November 13, 2018 21:33
Self looping polling function that waits until each request has finished before it waits before attempting another request. Can also be Cancelled.
/**
* Sleep timer that can also cancel the request
*
* @param ms
* @param isCancelled
* @returns {Promise<any>}
*/
const sleep = (ms, isCancelled) => {
let timeoutHandler;
@fokusferit
fokusferit / browserMocks.js
Last active May 14, 2018 15:11
Add Testing Strategy to preact-cli
// Mocks localStorage
const localStorageMock = (function() {
let store = {};
return {
getItem: (key) => store[key] || null,
setItem: (key, value) => store[key] = value.toString(),
clear: () => store = {}
};