Skip to content

Instantly share code, notes, and snippets.

Rich Harris Rich-Harris

Block or report user

Report or block Rich-Harris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Rich-Harris /
Last active Nov 20, 2019
Svelte style properties naive implementation

This is a copy of an early attempt to imagine an implementation of 'style properties' in Svelte, as described in this RFC. It is preserved here to satisfy curiosity, or in case we hate the new one.

Style properties — handily distinguishable from regular properties by the leading -- used by CSS custom properties — are passed down to components through a separate channel. The example at the top of this RFC might be converted to the following JavaScript:

const slider = new Slider({
  props: {
    value: ctx.value,
Rich-Harris /
Last active Apr 26, 2020
Testing array.splice vs array.pop vs set.delete

You have an array. Its sort order doesn't matter. You want to remove an item from this array.

The obvious thing to do would be to use splice:

function remove(array, item) {
  const index = array.indexOf(item);
  array.splice(index, 1);
Rich-Harris /
Last active Dec 20, 2019
Svelte vs Knockout
Rich-Harris / index.js
Last active Jan 22, 2020
whatwg stream utils
View index.js
const fs = require('fs');
const { ReadableStream, TransformStream, WritableStream} = require('web-streams-polyfill/ponyfill/es2018');
function createReadStream(file, opts) {
return new ReadableStream({
start(controller) {
const stream = fs.createReadStream(file, opts);
stream.on('readable', () => {
const data =;
Rich-Harris /
Last active Dec 20, 2019
Source bytes: React vs Ember Octane vs Svelte

I'm procrastinating instead of working on a conference talk, so I decided to implement this component in Svelte to see which framework is most expressive:

Screen Shot 2019-03-30 at 16 42 16

Ember Octane

Here's the original, with the addition of an import for dataUriAsSrc (and updated per @chriskrycho's comment):

Rich-Harris /
Last active Dec 20, 2019
Optimising CSS modules

Suppose you have an app like this, and your bundler turns .css files into strings:

// main.js
import './x-foo.js';
import './x-bar.js';

document.body.innerHTML = `<x-foo></x-foo><x-bar></x-bar>`;
Rich-Harris /
Last active May 22, 2020
What should be the canonical file extension for Svelte components?

So far, most of us have been writing Svelte components into .html files, with a few exceptions (Parcel users, for example, have additional constraints to work with). We're currently discussing whether this should change.

Once you've read the pros and cons, please vote!



  • It signals that you can use your existing HTML (and CSS) knowledge
  • Valid HTML is valid Svelte
Rich-Harris /
Last active Nov 20, 2019
Notes on Node streams

I have a real mental blockage around this stuff. Partly because the docs could probably be a little better, partly because it's changed over the years, probably partly because I'm dumb. Whatever. I'm going to try and document how to do stuff I occasionally need to do, so I can refer to it next time.

Return value of pipe

x.pipe(y) === y; // true
x.on(someEvent, callback) === x; // true

A concept diff from Svelte 2 to 3

-A component must have a default export, but the default export is not the component
-The default export and its properties must be structured a certain way, you can't just use JavaScript
-Components, actions, animations, transitions, custom events etc must be registered, not just imported
-Components can be registered with a shorthand, because the normal way is cumbersome
-methods are attached to the prototype, and `this` is the component, even though it looks (including to linters and typecheckers) as though the `methods` object itself is the context
-Events must be method calls, not arbitrary expressions
-`event` has a special meaning in method calls, as does `this`, as does `refs`, as do `console` and other special names
Rich-Harris /
Last active Jun 1, 2020
The truth about Svelte

I've been deceiving you all. I had you believe that Svelte was a UI framework — unlike React and Vue etc, because it shifts work out of the client and into the compiler, but a framework nonetheless.

But that's not exactly accurate. In my defense, I didn't realise it myself until very recently. But with Svelte 3 around the corner, it's time to come clean about what Svelte really is.

Svelte is a language.

Specifically, Svelte is an attempt to answer a question that many people have asked, and a few have answered: what would it look like if we had a language for describing reactive user interfaces?

A few projects that have answered this question:

You can’t perform that action at this time.