Skip to content

Instantly share code, notes, and snippets.

View PatrickJS's full-sized avatar

PatrickJS PatrickJS

View GitHub Profile
/* Features */
// - remove cache headers for /q-data.json
export const handler = async (event, context) => {
try {
const [req, res, ctx, target] = eventNormalize(event, context); // 'ctx' is the context object
// Your business logic here
// Example of modifying the response based on URI
if (req.uri.endsWith('/q-data.json')) {
res.headers['cache-control'] = 'no-cache';
const { readable, writable } = new TransformStream();
fetch('/send?channel=123', method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: readable,
});
const response = await fetch('/receive?channel=123');
const response_readable = response.body;
const machine = useConst(() => {
return {
state: 'off',
_machine: undefined,
send: $((newState) => {
return this._machine ||= noSerialize(createMachine(this))).send(newState)
)
};
})
@PatrickJS
PatrickJS / server-config-argument.js
Last active May 17, 2024 03:40
whats better server$ api?
const getData = server$((myArg) => {
console.log(myArg)
});
getData(new ServerConfig({
method: 'get'
}), myArg)
getData(serverConfig({
method: 'get'
import { isBrowser } from '@builder.io/qwik/build';
serverOnly();
export function serverOnly() {
if (isBrowser) {
console.log('SERVER ONLY');
throw new Error(
'This module cannot be imported from the Client.' +
'It should only be used from the Server.',
{
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
]
}
Qwik
Deprecated functions and their replacements
Deprecated Replacements
useWatch$ useTask$
useMount$ useTask$
useServerMount useTask$ + isServer
useClientMount useTask$ + isBrowser
useClientEffect useVisibleTask$
useClientEffectQrl useVisibleTask$
useBrowserVisibleTask useVisibleTask$
@PatrickJS
PatrickJS / method-missing-proxy.js
Created March 11, 2024 01:59 — forked from torgeir/method-missing-proxy.js
es6 proxies method missing example
/*
What happens?
- `new Type().what` is looked up with a call to `get` on the proxy
- a function is returned that will look up `METHOD_NAME` when called
- `METHOD_NAME` is called because of the `()` behind `new Type().what`
- if `METHOD_NAME` exists on you object, your own function is called
- if not, because of prototypal inheritance, `get` is called again
- `name` is now `METHOD_NAME` and we can throw as we know `METHOD_NAME` is not implemented on the type
credits http://soft.vub.ac.be/~tvcutsem/proxies/
<div
class={`flex aspect-square w-full grow flex-col items-center justify-center rounded-3xl ${
props.useBorder ? 'border-4 border-gray-200' : ''
} p-5 max-md:mt-10 max-md:max-w-full`}
>
<Lottie
path={props.lottie}
loop={props.loop}
speed={props.speed}
/>