This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
Compile server functions to other backend languages #19
Labels
enhancement
New feature or request
ideas wanted
Needs imaginative ideas to make work
server-side-rendering
Server based render methods
Currently Prism compiles functions for rendering components and pages. These functions are built up of string concatenations so are incredibly simple and fast. These also feature string escaping etc... But they are very generic and simple to create as most of the work is done during templating.
But Prism only compiles these functions for JS engine use. Many other server side rendered sites use other backend languages such as golang, rust, ruby, python, c#, c++, ... . Which is a problem for building isomorphic sites as manually adding ssr templating desyncs the process of client side and server side views and templating. There are currently ways of calling JS code in golang and such and some have used that to achieve ssr of react apps. But as Prism is a compiler and there is not lot of complexity in the render functions I don't think it would be to hard to add the ability to output native golang, rust, ruby... functions for use with a backend framework.
This would be beneficial:
Three current considerations:
.cshtml
. These seem to exist for DX, ease of use and compile time checking. However Prism offers all of this during compilation so they are not needed and add additional nuance. And prism output is designed to be run rather than analysed.Intl.NumberFormat
class does not exist in any other language in form or name. So sending it straight over to python would not work.But there could be something like:
That during ssr compile time could do some switching of the return expression ...
backendLanguage
asts
it will include all the type information in the.ts
server render function. (this works becomes of some specific things in chef and the fact ts is a superset of js. the ts info exists in the server module ast but is never rendered out...). It should be quite simple to transpile the interface ast (struct
for golang and rust). Howerver actual data types do not exist across languages. This should be simple for some things like arrays. However types likenumber
do not exactly map over. Whereasnumber
exists in ecmascript, in rust there areu8, u16, i8, f64, ....
and none of the quite match up. I think for this case it would be assumef64
and then you might have to do some casting when using this function. This problem is similar to the last point.This does sound quite complex to implement but I think it would be quite simple. Just implement a fraction of syntax into chef (no parsing just
render()
methods) and add some step for transpilation. There would need to be a little work to implement the structure to build to non js based languages but once that is done then I think adding support for a language would be simple (especially after the first language support is implemented).Implementing this would follow a common development characteristic of Prism where implement support for basic templating and add more complex templating later.
The text was updated successfully, but these errors were encountered: