Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Rich-Harris / strawman.md
Created March 29, 2018 23:05
Multiple spread attributes, in order, without unnecessary changes

This is based off work by @mrkishi, and is an attempt to do the following:

  • Multiple spread props on elements/components
  • Later props override earlier ones
  • Updates are conservative — we only set things that have actually changed
  • As much code in the shared library as possible

Given a situation like this...

@Rich-Harris
Rich-Harris / App.html
Created March 28, 2018 15:33 — forked from paulocoghi/App.html
Multiple components and store variables ($)
<InputAdd></InputAdd>
<List></List>
<script>
import InputAdd from './InputAdd.html'
import List from './List.html'
import { Store } from 'svelte/store.js';
@Rich-Harris
Rich-Harris / bookmarklet.js
Last active March 2, 2018 16:18
DebugClock bookmarklet
javascript:!function()%7B%22use%20strict%22%3Bfunction%20t(t)%7Breturn%20t*%3D-.002%2C%5B50*Math.sin(t)%2C50*Math.cos(t)%5D%7Dfunction%20e(t)%7Breturn%22hsl(%22%2BMath.max(0%2C90-.5*t)%2B%22%2C%20100%25%2C%2050%25)%22%7Dfunction%20n(e)%7Bfor(var%20n%3D%5B%5B0%2C0%5D%5D%2Ci%3De.lastTime%3Bi%3Ce.time%3Bi%2B%3D4)n.push(t(i))%3Breturn%20n.push(t(e.time))%2C%22M%22%2Bn.join(%22L%22)%2B%22Z%22%7Dfunction%20i()%7Bvar%20t%3Dfunction(t)%7Breturn%20document.createElement(t)%7D(%22style%22)%3Bt.id%3D%22svelte-731919397-style%22%2Ct.textContent%3D%22svg%5Bsvelte-731919397%5D%2C%5Bsvelte-731919397%5D%20svg%7Bposition%3Afixed%3Bright%3A1em%3Bbottom%3A1em%3Bwidth%3A100px%3Bheight%3A100px%7D%22%2Cf(t%2Cdocument.head)%7Dfunction%20r(t%2Ce)%7Bfor(var%20n%2Ci%2Cr%2Co%3De.frames%2C_%3D%5B%5D%2Cm%3D0%3Bm%3Co.length%3Bm%2B%3D1)_%5Bm%5D%3Ds(t%2Ch(%7B%7D%2Ce%2C%7Bframe%3Ao%5Bm%5D%2Ci%3Am%7D))%3Breturn%7Bc%3Afunction()%7Bn%3Dc(%22svg%22)%2Ci%3Dc(%22g%22)%2Cr%3Dc(%22circle%22)%3Bfor(var%20t%3D0%3Bt%3C_.length%3Bt%2B%3D1)_%5Bt%5D.c()%3
@Rich-Harris
Rich-Harris / ls.c
Created February 8, 2018 23:07
simple ls replacement for very large directories
#include <stdio.h>
#include <dirent.h>
int main (int argc, char *argv[ ])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2) {
fprintf(stderr, "usage: ls directory_name\n");
@Rich-Harris
Rich-Harris / README.md
Created December 20, 2017 15:57
import from async

The fundamental problem with top-level await is that it prevents two unrelated modules doing asynchronous work in parallel, because module evaluation order is strictly deterministic.

What if we provided an escape valve that relaxed that constraint?

// main.js
import foo from async './foo.js';
import bar from async './bar.js';
import baz from './baz.js';
@Rich-Harris
Rich-Harris / README.md
Created December 14, 2017 15:35
svelte-kit-scroller

Am planning to open source this when I get some breathing room, but a gist will do for now.

Usage:

<Scroller top=0.2 bottom=0.8 threshold=0.5 bind:index bind:offset bind:progress parallax>
  <div slot='background'>
    <!-- fixed, or parallaxing (if the parallax option is set) background -->
  </div>
@Rich-Harris
Rich-Harris / output.html
Created December 4, 2017 20:19
out-of-order streaming SSR
<body>
<header>
<h1>Hello world!</h1>
</header>
<main>
<noscript id='__await_block_0_start'></noscript>
<p>loading...</p>
<noscript id='__await_block_0_end'></noscript>
</main>
@Rich-Harris
Rich-Harris / README.md
Created November 24, 2017 16:44
how svelte/store could work

Bear with me while I think aloud about this (please comment there, not here!). Goals:

  • Minimal boilerplate
  • Familiar API
  • Preserve Svelte's built-in optimisations
  • Support use cases like hot-reloading and custom devtools

Let's start with a single store that is external to the component tree. Our top-level <App> component connects to it:

@Rich-Harris
Rich-Harris / README.md
Last active May 31, 2019 14:40
rollup-plugin-unpkg behaviour

From this Twitter convo. It would be cool to have a plugin that allowed you to use bare module specifiers (import * as React from 'react') in your app, and converted them to unpkg.com URLs.

Say you have these two source files:

// main.js
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import message from './message.js';
@Rich-Harris
Rich-Harris / README.md
Last active January 25, 2023 19:03
Unifying Rollup options

Rollup 0.48 introduces a few changes to the options object, because the current options are confusingly different between the CLI and the options exported by your config file.

Changes to the config file

  • entry is now input
  • sourceMap and sourceMapFile are now sourcemap and sourcemapFile (note casing)
  • moduleName is now name
  • useStrict is now strict

The dest and format options are now grouped together as a single output: { file, format, ... } object. output can also be an array of { file, format, ... } objects, in which case it behaves similarly to the current targets. Other output options — exports, paths and so on — can be added to the output object (though they will fall back to their top-level namesakes, if unspecified).