Notes on JavaScript events, after a stray use of e.stopPropogation
on a recursive component and reading this excellent article.
- They go through 3 phases: capturing (from root to target), targeting (at target), bubbling (from target back up to DOM room)
- You can track which phase you're at with
e.eventPhase
: 1 = capture, 2 = target, 3 = bubble, 0 = none e.stopImmediatePropogation
is more aggressive thanstopPropogation
: the former prevents any further events on the same node, whereas the latter actually does not.
an assortment of fun facts from css-for-js.dev:
on colors: you can use hsl (hue, saturation, lightness) instead of hex codes for color which is a bit more intuitive!
rem vs em vs px:
rem
is always relative to the root element, andem
to current element- don't set a px font size on html selectors, because that overrides the user's chosen default, and is bad for accessibility
px
is ideal for padding and margin, since we usually don't need spacing to scale (but we do for text size)
cool devtools trick: you can comment out styles in a css file but devtools will still show the option for you to toggle on
border-box: box-sizing: border-box
enables things to behave a lot more intuitively. for example, the width of a box includes border and padding
border-radius: there is a list of mistakes the csswg publishes, and one of them is that border radius should have been corner radius...
Started reading the Rust Book today, and went down a mini rabbit hole of how it handles semantic versioning.
Say I define a package in my Cargo.toml
as:
[dependencies]
rand = "^0.8.5"
In JS world, we might do the same in package.json or for Ruby in a Gemfile.
While yarn, npm, or bundler will check for versions up to (but not including) 1.0.0, Cargo checks up to only 0.9.0. Cargo has special rules for versions before 1.0.0, where for 0.y.z, y is considered potentially breaking.
After 1.0.0, it will follow convention and check between the major version releases.
If I define a specific version like rand = "0.8.5"
in my Cargo.toml
, it is equivalent to "^0.8.5"
. This is also unlike JS/Ruby, where defining the specific version like 0.8.5 means that the package manager installs exactly 0.8.5.
If I want to define the exact version, I'd write rand = "=0.8.5"
.
Of course, there's a lockfile so builds are consistent.
I'm at the Recurse Center for the next five weeks! Trying out this ~composting system~ where I shall fling scraps of thought, ideas, code etc throughout my batch, instead of putting pressure on myself to produce polished pieces of writing. (Hopefully this page will become more polished over time, but I'm not holding myself to that either.) Excited to write more code than words this season!
Wrote a tiny shell script to write scraps, so scrap [title]
produces and opens a new markdown file :'). Initially forgot that I needed to do chmod -x
to make the file executable.
(If you're looking for older posts, I also have some words on advice for the new grad software engineer, open source work at The New York Times, and using RecordRTC with React.)