primatejs / primate

Web framework focused on flexibility and developer freedom
https://primatejs.com
MIT License
211 stars 9 forks source link

bare imports #159

Open terrablue opened 3 months ago

terrablue commented 3 months ago

Global bare imports.

import target from "#app/target";

target; // "desktop" | "web"
import IndexPage from "#components/IndexPage.jsx";

export default {
  get() {
     // statically (TS), this needs to resolve to the correct component for live-bindings between server and client
     // in runtime (JS), this needs to resolve to `view("IndexPage", props);`
     return IndexPage({ posts: [{ id: 0, title: "Hello, world!" }] });
  },
};

(Relates to https://github.com/primatejs/primate/issues/122)

Other uses also possible, like importing stores from anywhere, provided we can make sure that operations are still transactionalised.

With export conditions, we should even make it possible to import stores from clientside components, translating the implementation to a fetch call to some canonical API route that accesses the database and returns the results. But this could quickly become a security nightmare unless done conservatively and in an extremely guarded way (only reads, and possibly hardcoding the queries on the server so it doesn't become a universal mechanism to access the database).

Considerations:

Is currently only possible with Node, as introducing custom loaders isn't supported in Bun (https://github.com/oven-sh/bun/issues/13415) or Deno (https://github.com/denoland/deno/issues/23201). We can only mainline this once Bun and Deno support it.