Web development notes
Modern web dev stuff I am, after all, learning while working on a WYTIWYS (What You Tree Is What You Search) corpus query interface and a recipe website for programmers.
Nodenotes
Setting up nvm (Node Version Manager)
- install
nvmfrom your package manager - add
. /usr/share/nvm/init-nvm.shto the shell config file.
Installing version n of Node
nvm install n
Using version n of Node
nvm use n
Installing a TypeScript project
npm install
Using a local module in a TypeScript project
- package the module into a
.tgz:npm pack - move to the project folder and install the package:
npm install --save PATH-TO-TGZ
CSS
Hiding stuff
visibility: hiddenis like the invisibility cloak (the element becomes transparent, but still takes up space)display: noneprevents the element from showing up at all
Selectors
Basic selectors:
*tag.class#id[attribute]
Useful combinations:
tag.class(alltags of a given class).class tag(alltags that are descendants of a tag with a givenclass).class>tag(alltags that are direct descendants (children) of a tag with a givenclass)tag[attribute](alltags with a givenattribute).class1.class2(all elements that have bothclass1andclass2)
TypeScript
Array concatenation
Given
const a: number[] = [1, 2];
const b: number[] = [3, 4];
const c: number[] = [5];
-
spread operator:
const abc = [...a, ...b, ...c]; -
concatmethod:const abc = a.concat(b).concat(c);but also:
const abc = a.concat(b, c);and even:
const abc = a.concat(3, 4, 5); // wild!
Last element of an array
xs.slice(-1)[0]
Introspection
Two operators:
typeof XOBJ instanceof TYPE
Integer to string and vice versa
int.toString();
parseInt(str, base);
Lambdas
(par1: type2, par2: type2): returnType => expression
JSON object operations
Kinda like a Python dictionary:
- does a
jsonobject have a certainkey?key in json - delete a
key-value pair from ajsonobject:delete json[key] - add a
key-valpair to ajsonobject:json[key] = val
Ternary operator
I guess Javascript is a bit like Java:
condition ? what_if_true : what_if_not
React
Using variables
{variable}
Passing a tag its props
If a tag was a function, props would be its (named) parameters:
<Tag propName={propVal}/>
<!--or simply-->
<Tag {propVal}/>