Hacker News new | ask | show | jobs
Viewi – build reactive web applications with PHP (viewi.net)
14 points by ivan_voitovych 1621 days ago
3 comments

If I understand this is a fairly straightforward source-to-source PHP-to-Javascript compiler. It is so simple that when complied to Javascript it uses Javascript semantics!

If a PHP look is all that matters I guess it is useful, however the semantic difference between the two languages would be both a pain to work with an a footgun. You are essentially writing two languages at once and you will need lots of diligent testing to ensure that the two behave the same if you ever want to run the same code on the client and server. From my pessimistic viewpoint it looks like using the same code on client and server is not going to work with this approach.

If I was writing this I would have tried to make a much more faithful implementation of PHP. Obviously you can't directly connect to your database from the browser but I would try to make the code behave identically (within the supported features). This would likely result in slower code on the client but at least it would be predictable.

Well, your point is valid. You do need a lot of testing. A lot of your concerns are mentioned in the docs. The point is, whatever is possible to do in the browser you write in your component. Need something from the DB, etc. - you use HttpClient to talk to the server. Faithful implementation - there are Livewire, Yoyo dev, etc. They run PHP on the server only. Your feedback is highly important for me, thank you This helps me to improve my solution and provide the best quality
This looks good, but it is not clear what the limitations are (says it works with a subset of PHP), how does this compare to say Laravel Livewire?

It's also not clear how it works, the code examples are missing a lot of information.

For example you have Counter.php, and Counter.html, how are they connected? And then you use it as <Counter /> ?

There is a documentation. In particular here https://viewi.net/docs/introduction you can read more about how it works, about the base idea and concept. About the limitations, some of them are described here https://viewi.net/docs/caveats and in general - you can't use functionality and features that are meant for server side only. Viewi is not the same as Livewire, it works differently and it's not tied to a specific framework. Counter php and HTML, the same name and location and you get yourself a component, nothing else is needed, use it as a tag, more here https://viewi.net/docs/components. I appreciate your questions, will work on improvements with the explanation and examples.
Looks interesting. Is there a benefit specific to using PHP for building the UI, like access to PHP libraries, etc.? Or is it for people already using PHP on the server-side, so they can also use the same language for the client-side?
It's for PHP developers mostly, who want to build SPA but struggle with JavaScript frameworks, or who want SPA as well as efficient SSR without involving Node js on their servers. Plus, it's already familiar php and html, similar template syntax as in Angular or Vue.