Adds some snippets for web stuff

This commit is contained in:
Jonathan Hodgson 2019-08-21 15:50:12 +01:00
parent 95a85a6893
commit bd847bd812
4 changed files with 97 additions and 4 deletions

View file

@ -0,0 +1,39 @@
priority 1000
snippet class "Adds a class"
class ${1:class_name}{
/**
* this function is run as soon as possible.
* the dom isn't neccessarily loaded / parsed
**/
constructor(){
//Bind this in the following functions to the class
this.domloaded = this.domloaded.bind(this);
//check to see if the dom has loaded yet
if(document.readystate == "loading"){
//if the dom hasn't loaded, wait until it is
document.addeventlistener("readystatechange",this.domloaded);
return;
} else {
//if it has, run the domloaded function
this.domloaded();
}
}
/**
* this function is run as soon as the dom is loaded
**/
domloaded(){
//make sure we don't run this twice
document.removeEventListener("readystatechange",this.domloaded);
}
}
new $1();
$0
endsnippet
snippet bind "creates a bind statement"
this.${1:functionName} = this.$1.bind(this);
endsnippet