I've been playing around with a similar idea using nextjs. My idea was to create some kind of RPC interface with typescript that works seamlessly between server/client rendering, so during server rendering, RPC calls would just be regular function calls, and during client rendering/event handling, the calls would be made through sockets or HTTP requests. There's a lot of criticism in this thread. I'm curious if you'r…
Show HN: Purview – A server-side component framework
41–50 of 56 posts
Re: Show HN: Purview – A server-side component framework
#42Re: Show HN: Purview – A server-side component framework
#43So now we're stuffing sql in our react as well as html and CSS? React is on course to reinvent the PHP that everyone spent so long laughing about
If you have a complex front-end and back-end with a REST API, each time you modify a server route, you need to find all instances in your client where you make an AJAX request to that route and change them appropriately. The potential for inconsistency can cause numerous bugs.
GraphQL solves this by having a very flexible and standardized server (albeit complex), giving your client access to arbitrary structured information using a query language.
Purview solves this by moving your logic to the server-side, where you can access your database directly. Because everything runs on the server, the client-server interface is abstracted away, and you don't need to worry about using GraphQL or REST. You can make database queries, contact external services, etc. directly within your components.
To keep this maintainable, you split up your page into logical, reusable components, just like you would with React, and each component now not only contains your view logic, but also the server-side logic. Given that you've decomposed your components well, this makes it easy to reason about the whole system when it comes to any part of your page.
Re: Show HN: Purview – A server-side component framework
#44Re: Show HN: Purview – A server-side component framework
#45Huh? React components can run on the server side, that is one of the primary benefits of React compared to its predecessors.
Re: Show HN: Purview – A server-side component framework
#46Earlier quoted context omitted.
Why's that garbage? Sometimes a full SPA is not needed.
Just take a step back and look at it, you're combining HTML, SQL and JS, on the fucking server.
Re: Show HN: Purview – A server-side component framework
#47Re: Show HN: Purview – A server-side component framework
#48> What if your React components ran on the server-side? Huh? React components can run on the server side, that is one of the primary benefits of React compared to its predecessors.
Re: Show HN: Purview – A server-side component framework
#49so it's a next.js clone?
Re: Show HN: Purview – A server-side component framework
#50Earlier quoted context omitted.
Yes, that was my inspiration! Chris gave a great talk about it at ElixirConf is anyone is interested in watching: https://www.youtube.com/watch?v=Z2DU0qLfPIY Some differences compared to LiveView: - Type-checking: there are extensive JSX typings ( https://github.com/karthikv/purview/blob/master/src/types/js... ) that ensure you're attaching event handlers with the correct signatures, specifying supported props, using…
Neat project! We indeed support nesting in LiveView :)
- I noticed that you said you use morphdom for LiveView. I originally started with this too, but found that the DOM diffing doesn't work well with any client-side JS that may modify the page (e.g. a date picker, a tooltip library, a custom dropdown, etc.). I ended up switching to snabbdom (https://github.com/snabbdom/snabbdom/), a virtual DOM implementation, to avoid updating parts of the page that the user doesn't directly intend to modify. This helps with client-side interop, and it also gave us a nice boost in performance. Did you run into any similar issues with LiveView? Do you still use a DOM diff rather than a virtual DOM diff?
- On that note, what's the recommend way to interop with client-side libraries like I mentioned earlier? We use the WebComponents custom-elements spec to define custom tags that encapsulate client-side JS logic (e.g. we have an , a , etc.), and then in our Purview components we can just send down these tags. We also had to provide the ability to integrate with DOM events triggered by these custom elements. Is there a recommended approach in LiveView to integrate with these libraries?
- With respect to nesting in LiveView, do you call live_render() directly within a view's render() function? Do you pass props in this call? There doesn't seem to be a differentiation between props and state for LiveView--are both consolidated into "assigns"? Hence both are mutable? I'm aware that you use immutable data structures in Erlang/Elixir, but I mean in the sense that you can assign a different value to a prop that was given to you by your parent. If this is the case, how would that work if there's a re-render and the prop passed by the parent changes?