Skip to content

Instantly share code, notes, and snippets.

View JoviDeCroock's full-sized avatar
🐨

Jovi De Croock JoviDeCroock

🐨
View GitHub Profile
@JoviDeCroock
JoviDeCroock / diff.js
Created October 27, 2020 19:54
Progressive hydration
// TODO: code
import { useClient } from 'urql';
export const ComponentThatWontRerender = () => {
const client = useClient();
const mutate = async () => {
const result = await client.mutate(...).toPromise()
console.log(result)
}
return <PoseMirror />
const AnimateMountUnmount = ({ mountClass, unmountClass }) => {
const [mounted, setMounted] = useState(false);
const [unmounting, setUnmounting] = useState(false);
// Can also be attached with useImperativeHandle to the parent.
const unmountSignal = () => {
setUnmounting(true)
}
useEffect(() => {
var App = Object(preact_compat__WEBPACK_IMPORTED_MODULE_0__["memo"])(_c = _s2(function App2(props) {
_s2();
var _useCounter = Object(_useCounter__WEBPACK_IMPORTED_MODULE_1__["useCounter"])(0),
_useCounter2 = _slicedToArray(_useCounter, 2),
count = _useCounter2[0],
increment = _useCounter2[1];
return Object(preact_compat__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, Object(preact_compat__WEBPACK_IMPORTED_MODULE_0__["h"])("p", null, "Count: ", count), Object(preact_compat__WEBPACK_IMPORTED_MODULE_0__["h"])("button", {
onClick: increment
@JoviDeCroock
JoviDeCroock / *cjyes.md
Created May 20, 2020 18:50 — forked from developit/*cjyes.md
more-or-less instant command-line ESM to CJS transform. Copies from src to dist. `cjyes src/*.js`

cjyes npm version

🔍 see jay, yes! 🎉 / 👨🏻‍💻 see, JS! 👾 / ⚓️ sea JS ⛴

If you're publishing ES Modules, you need to also publish CommonJS versions of those modules.

This isn't to support old browsers or Node versions: even in Node 14, using require() to load a module won't work if it's only available as ESM.

cjyes is the bare minimum fix for this problem. You write ES Modules and fill out a valid package.json, and it'll generate the corresponding CommonJS files pretty much instantly. cjyes takes up 500kb of disk space including its two dependencies.

Strict-equality

When creating elements and passing them as children we can have scenario's where we don't have to diff the children because it will still be the same vnode.

Imagine the following scenario:

const context = createContext(null);
const App = () => (

Problem

Imagine a scenario where we dispatch two requests one to get our Todo named Q and one to toggle our todo to completed named M1.

Q1 will return:

{
  id: 1
 name: 'make graphcache updates idempotent',
#!/usr/bin/env node
export function foo() {
return 'hello world';
}
import { Exchange } from 'urql';
import { fromDomEvent, subscribe, pipe, filter } from 'wonka';
export const offlineExchange = (): Exchange => ({
forward,
client,
}) => {
const queue = [];
const flushQueue = () => {
const seen = []
function traverseObject(obj) {
Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
if (typeof value !== 'object) return { ...acc, [key]: value };
if (Array.isArray(value) {
return { ...acc, [key]: value.map(traverseObject) }
}