Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nadav/handle route exports #1225

Merged
merged 14 commits into from
Oct 14, 2024
2 changes: 1 addition & 1 deletion packages/app-core/src/define-app-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export interface EditablePointOfInterest {
}

export interface IResults<T> {
status: 'ready' | 'invalid' | 'disposed';
status: 'ready' | 'invalid' | 'disposed' | 'loading';
results: T | null;
errorMessage?: string;
}
Expand Down
59 changes: 59 additions & 0 deletions packages/define-remix-app/src/handle-proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
export const createHandleProxy = () => {
const lastLoadedHandleRef: { current: any } = { current: null };
const handle = new Proxy({}, {
get: (_, prop) => {
return lastLoadedHandleRef.current?.[prop] as unknown;
},
apply(_, thisArg, argArray) {
return lastLoadedHandleRef.current?.apply(thisArg, argArray);
},
construct(_, argArray) {
return new lastLoadedHandleRef.current(...argArray);
},
defineProperty(_, property, attributes) {
return Object.defineProperty(lastLoadedHandleRef.current, property, attributes);
},
deleteProperty(_, p) {
return delete lastLoadedHandleRef.current[p];
},
getOwnPropertyDescriptor(_, p) {
return Object.getOwnPropertyDescriptor(lastLoadedHandleRef.current, p);
},
getPrototypeOf(_) {
return Object.getPrototypeOf(lastLoadedHandleRef.current);
},
has(_, p) {
return p in lastLoadedHandleRef.current;
},
isExtensible(_) {
return Object.isExtensible(lastLoadedHandleRef.current);
},
ownKeys(_) {
return Object.keys(lastLoadedHandleRef.current)
},
preventExtensions(_) {
return Object.preventExtensions(lastLoadedHandleRef.current);
},
set(_, p, newValue) {
lastLoadedHandleRef.current[p] = newValue;
return true;
},
setPrototypeOf(_, v) {
return Object.setPrototypeOf(lastLoadedHandleRef.current, v);
},


});
return {
handle,
setHandle: (handle: any) => {
lastLoadedHandleRef.current = handle;
}
};
}
17 changes: 17 additions & 0 deletions packages/define-remix-app/src/links-proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { LinksFunction } from "@remix-run/node";

export const createLinksProxy = () => {
const lastLoadedLinks: { current: null | LinksFunction } = { current: null };
const linksWrapper = ()=>{
if(lastLoadedLinks.current){
return lastLoadedLinks.current();
}
return [];
}
return {
linksWrapper,
setLinks: (linksFunction: LinksFunction) => {
lastLoadedLinks.current = linksFunction;
}
};
}
Loading