kaleidawave / prism

(No longer in development). Experimental compiler for building isomorphic web applications with web components.
MIT License
110 stars 1 forks source link

Compile server functions to other backend languages #19

Open kaleidawave opened 4 years ago

kaleidawave commented 4 years ago

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:

But there could be something like:

@returnValueIfUnderNonJSBackendLanguage(`f"{x:,.3f}"`)
function formatNumber(x: number) {
    return new Intl.NumberFormat('en').format(x)
]

That during ssr compile time could do some switching of the return expression ...

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.