Skip to content

Instantly share code, notes, and snippets.

View arv's full-sized avatar
👋
Reflecting...

Erik Arvidsson arv

👋
Reflecting...
View GitHub Profile
@arv
arv / README.md
Last active February 10, 2023 16:19
Replicache MemStore

MemStore

This is the MemStore implementaion as used in Replicache 12.1

This depends on files not included in this gist but these should be pretty self describing.

@arv
arv / example.ts
Last active November 17, 2022 08:43
A simple TypeScript Immutable type
import type {Immutable} from './immutable.js';
type Todo = {
id: string;
done: boolean;
order: string;
text: string;
};
type ImmutableTodo = Immutable<Todo>;
@arv
arv / README.md
Last active April 11, 2022 09:54
fractional-indexing and Jest
node --version # v17.9.0
npm --version # 8.5.5
npm install
npm run test
import { useEffect, useState } from "react";
import { MutatorDefs, Replicache, ReplicacheOptions } from "replicache";
export function useReplicache<MD extends MutatorDefs>(
opts: ReplicacheOptions<MD>
): Replicache<MD> | null {
const [rep, setRep] = useState<Replicache<MD> | null>(null);
useEffect(() => {
const r = new Replicache(opts);
setRep(r);
<!DOCTYPE html>
<script src="url.js"></script>
<script>
var url = new URL('http://www.example.com/a/b/c.html?p=q&r=s&p&p=t#hash');
for (var key in url) {
console.log(key, url[key]);
}
@arv
arv / Document.registor.md
Last active December 30, 2015 19:38
document.register with a functionThe main difference between this and the current LC is that it takes a Function object instead of an Object. The Function's @@create method is updated to create instances that are real elements.

Register

When called, the register method must run these steps:

Input

  • ENVIRONMENT, the unit of related similar-origin browsing contexts
  • DOCUMENT, the context object of the method
  • NAME, the custom element name of the element being registered
  • FUNCTION, the custom element constructor function, optional
@arv
arv / gist:6528418
Created September 11, 2013 19:17 — forked from sorvell/gist:6527156
<!DOCTYPE html>
<html>
<head>
<script src="../polymer/polymer.js"></script>
</head>
<body>
<template id="host-template">
<div>host shadowRoot</div>
<content></content>
</template>
@arv
arv / soduko.js
Last active December 18, 2015 08:28 — forked from BrendanEich/gist:5753666
ES6 syntax
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
@arv
arv / compile.sh
Last active December 17, 2015 04:59
Shows how you can build a smaller js binary to only parse (and print) some ES6 code.
traceur --out out.js parser.js
# Traceur does not strip dead code. Use Uglify2.
uglifyjs src/runtime/runtime.js out.js -cm -o out.min.js
@arv
arv / DOMImpl.js
Last active December 11, 2015 23:18
document.register with classes
// Create is defined in the latest ES6 spec. Foo[create]() is used to create the instance
// when you do "new Foo". This instance is then passed to Foo.call(instance, <args>)
import {create} from '@reflect';
Element[create] = function() {
return documemt.createElementNS(this.prototype.namespaceURI, this.prototype.localName)
};