import { hook, OptionsTypes } from './preact-options-helper.ts';
hook(OptionsTypes.RENDER, (old, vnode) => {
let component = vnode.__c;
if (component) {
// do stuff with the component instance
} else {
console.log(vnode.props);
}
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"/> | |
| <title>exhaust() vs ternary #jsbench #jsperf</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
| <script src="./suite.js"></script> | |
| </head> | |
| <body> | |
| <h1>Open the console to view the results</h1> |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"/> | |
| <title>bare-bones exhaust() vs ternary #jsbench #jsperf #jsbench #jsperf</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
| <script src="./suite.js"></script> | |
| </head> | |
| <body> | |
| <h1>Open the console to view the results</h1> |
This file contains hidden or 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
| /** | |
| * useSignal, but works as a ref on DOM elements. | |
| * @template T | |
| * @param {T} value | |
| */ | |
| export function useSignalRef(value) { | |
| const ref = /** @type {Signal<T> & { current: T }} */ (useSignal(value)); | |
| if (!('current' in ref)) Object.defineProperty(ref, 'current', refSignalProto); | |
| return ref; | |
| } |
This file contains hidden or 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 { useSignal, signal, effect } from '@preact/signals'; | |
| import { useLayoutEffect, useMemo, useRef } from 'preact/hooks'; | |
| /** @template T @typedef {T extends (infer U)[] ? U : never} Items */ | |
| /** @param {{ v, k?, f }} props */ | |
| const Item = ({ v, k, f }) => f(v, k); | |
| /** | |
| * Like signal.value.map(fn), but doesn't re-render. |
All of the following values for the <script type=" ••• "> will cause inline or external JavaScript to execute:
| Value | Note |
|---|---|
"" |
The default value of script.type (eg: no type attribute present) |
"text/javascript" |
The official JavaScript MIME type |
"application/javascript" |
Legacy MIME type from when semantics mattered |
"text/x-javascript" |
Legacy MIME type from before JavaScript was accepted as a valid MIME type |
This file contains hidden or 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 { createContext } from 'preact'; | |
| import { useContext, useRef, useMemo, useState, useLayoutEffect } from 'preact/hooks'; | |
| function createSlotContext() { | |
| const slots = {}; | |
| const owners = {}; | |
| const subs = []; | |
| const sub = (name, fn) => { | |
| const e = [name, fn]; | |
| subs.push(e); |
This file contains hidden or 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 { signal, effect } from "@preact/signals-core"; | |
| interface CustomStorage { | |
| getItem(key: string): void; | |
| setItem(key: string, value: string | null): void; | |
| } | |
| /** | |
| * A version of signal() that persists and recalls its value in localStorage. | |
| * |
It's computed(), but with a second argument that gets passed each newly returned value in order to produce a string cache key. If you return the same cache key as the previous run of the computed, no update will be performed (no effects, no renders, etc).
- computed(
- () => ['an', 'unstable', 'return', 'value'],
- )
This file contains hidden or 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
| #!/usr/bin/env node | |
| /* eslint-disable no-param-reassign, no-fallthrough, guard-for-in, require-atomic-updates */ | |
| const path = require('node:path'); | |
| const {Worker} = require('node:worker_threads'); | |
| const DEBUG = {parsing: false, timing: false}; | |
| const debugEnv = process.env.DEBUG; | |
| if (debugEnv) { | |
| for (const name in DEBUG) { |