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
/* | |
* Showcase Example: Fetching Data via a Worker | |
* | |
* In this example, data is stored and fetched from a worker. | |
* It mimics the classic fetch behavior but instead passes the request through a worker. | |
* At request time, you can enhance the logic (e.g., add additional hashes) | |
* and at response time, perform parsing or other heavy-lifting operations. | |
*/ |
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 http from "http"; | |
import wsUtils from "y-websocket/bin/utils"; | |
import * as Y from "yjs"; | |
import WebSocket from "ws"; | |
const server = http.createServer(app); | |
const wss = new WebSocket.Server({ server }); | |
const docs = new Map < string, Y.Doc> (); |
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
let pyDoc = new Y.Doc(); | |
let provider: IndexeddbPersistence; | |
let wsProvider: WebsocketProvider; | |
const pxSync = (email, perseed) => { | |
return resource(function* (provide) { | |
if (!email) { | |
return; | |
} |
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
//this code is just for guidance. | |
import { each, main, on, resource, sleep } from "effection"; | |
import { | |
createThunks, | |
keepAlive, | |
mdw, | |
parallel, | |
put, | |
run, |
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 type { Result } from 'starfx'; | |
export function isJSONString(str) { | |
try { | |
const obj = JSON.parse(str); | |
return typeof obj === 'object' && obj !== null; | |
} catch (error) { | |
return false; | |
} | |
} |
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 { createSelector } from 'starfx'; | |
/* SELECTORS */ | |
/** | |
* Creates a proxy around an object to track accessed properties. | |
* | |
* @param {object} obj - The object to create a proxy for. | |
* @returns {[object, Set<string>]} An array containing the proxy object and a Set of accessed property names. | |
*/ | |
function trackAccesses(obj) { |
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 { createSelector } from "starfx/store"; | |
/* SELECTORS */ | |
/** | |
* Creates a proxy around an object to track accessed properties. | |
* | |
* @param {object} obj - The object to create a proxy for. | |
* @returns {[object, Set<string>]} An array containing the proxy object and a Set of accessed property names. | |
*/ | |
function trackAccesses(obj) { |
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 { createApi, createThunks, Err, mdw, Ok, put, sleep, spawn, take } from 'starfx'; | |
import { service } from '@app/service/delphiService'; | |
import { schema } from './schema'; | |
import { mainWorker } from './workers/workerApi'; | |
import type { Next, ApiCtx, Result } from 'starfx'; | |
import type { ThunkCtx } from '@app/types'; |
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
// we could store on filesystem as well... | |
export async function setPersisted(req: Request) { | |
const group = Object.values(req.session.groups || {}).find( | |
(x) => x.PERSEED === req.session.INSIDER | |
); | |
if (!group) { | |
console.log("setPersisted", "no group found"); | |
return {}; | |
} |
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
function* fetchRace(endpoint:string, timeout: number) { | |
let result: Response | null = null; | |
function* fetcher(endpoint: string, signal: AbortSignal) { | |
try { | |
result = yield* call(() => fetch(endpoint, { signal })); | |
} catch (error) { | |
console.error("fetchRace error", error); | |
} | |
} | |
const controller = new AbortController(); |
NewerOlder