This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/64927639 | |
function addPushStateListener(listener) { | |
if (!Proxy) return; | |
window.history.pushState = new Proxy(window.history.pushState, { | |
apply: (target, thisArg, argArray) => { | |
target.apply(thisArg, argArray); | |
listener(); | |
}, | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function onPathChange(callback) { | |
let path; | |
// Only reliable way seems polling across browsers :-( | |
setInterval(() => { | |
if (window.location.pathname !== path) { | |
path = window.location.pathname; | |
callback(path); | |
} | |
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rules = Array.from(document.getElementsByTagName("style")) | |
.map((el) => el.innerText.split("}")) | |
.flat() | |
.map((rule) => rule.trim()) | |
.filter((rule) => rule && !rule.startsWith("@")) | |
.map((rule) => { | |
return { | |
selector: rule.split("{")[0].trim(), | |
style: rule.split("{")[1].trim(), | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function memoize<R, T extends (...args: any[]) => R>(f: T): T { | |
const cache = new Map<string, R>(); | |
return ((...args: any[]) => { | |
const key = JSON.stringify(args); | |
if (!cache.has(key)) cache.set(key, f(...args)); | |
return cache.get(key); | |
}) as T; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
export function TestComponent() { | |
return React.createElement("div", {}, "Hello World") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react" | |
import { Frame, Stack } from "framer" | |
function capitalize(name) { | |
// Capitalizes a word: feed -> Feed | |
return name.charAt(0).toUpperCase() + name.slice(1) | |
} | |
function Button({ title, active, onTap }) { | |
const opacity = active ? 1 : 0.35 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
/** | |
A hook to simply use state between components | |
Warning: this only works with function components (like any hook) | |
Usage: | |
// You can put this in an central file and import it too | |
const useStore = createStore({ count: 0 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
export class Keyboard extends React.Component { | |
state = { key: null }; | |
onChange = event => { | |
this.setState({ key: event.target.value }); | |
}; | |
render() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<video controls autoplay muted> | |
<source id="mp4" src="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4" type="video/mp4"> | |
</video> | |
</body> | |
</html> |
NewerOlder