OptiSnippets
Repo for VSCode snippets
gbl
declare global {
interface Window {
store?: any;
utag?: any;
dataLayer?: any;
packageSearchPanelStore?: any;
}
}
ifee
(() => {
"use strict";
})();
ifeeint
(() => {
"use strict";
const myInterval = setInterval(() => {
const myElement = document.querySelector<HTMLElement>('selector');
if (myElement) {
clearInterval(myInterval);
}
}, 300);
setTimeout(function() {
if(myInterval) {
clearInterval(myInterval)
}
}, 15000)
})();
utag
window.utag.link(
{
eventAction: "Optimisation Event",
eventCategory: "Optimisation",
eventName: "",
event: "tiq.on",
},
"",
[]
);
stg
window.store.getState()
std
window.store.dispatch({
})
sts
window.store.subscribe(() => {
})
pstg
window.packageSearchPanelStore.getState()
pstd
window.packageSearchPanelStore.dispatch({
})
psts
window.packageSearchPanelStore.subscribe(function() {
})
getlang
const getLanguage = (): string => {
return window.location.hostname.match(/(uk|se|fi|no|dk)/i)[1];
}
debounce
const debounce = (func: Function, wait = 300, immediate = false) => {
var timeout;
return function () {
var context = this,
args = arguments;
var later = function () {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}