chinedufn / percy

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
https://chinedufn.github.io/percy/
Apache License 2.0
2.26k stars 84 forks source link

Custom Components #139

Closed rickihastings closed 4 years ago

rickihastings commented 4 years ago

I've implemented custom components in Percy, similar to what you see in React, so users can use a <MyComponent/> pattern rather than {my_component()} which feels a bit more up to date with competitor frameworks.

I've had to implement a list of valid html tags to do this (I took them from here).

If this isn't the best way of going around this please let me know, or if this is an unwanted change then that's fine too.

I tried to implement children in the same way React handles them, ie a children prop gets added into the child component but I've been round in circles with this - I kept hitting borrowing problems. I also had a look how Yew does it (which is similar to React) and still couldn't figure out a nice way of doing it. Any help on this would be appreciated. Children actually do work but they're just appended to the end of the parent, like in the normal HTML tags. I'm hoping it wouldn't require a huge refactor for it.

chinedufn commented 4 years ago

@rickihastings thanks so much for all of your awesome PRs!

If you don't mind - I want to take a few days to marinate on this.

Reason being is I've been thinking through a complete overhaul of the component / data / state model that Percy's libraries encourage.

I'm drawing some inspiration from specs - which has "systems" that for the most part are structs that implement a trait that describe what data they need to run.

Then all data is inserted into a World and different systems grab whatever they need from that world.

It feels so seamless that I want to experiment with a similar pattern in the browser development realm.

So this could very well fit into that model just fine - I just want to take some time to sketch out a first draft of what the direction might look like - get your feedback on it - and make sure this PR as it stands fits into that vision nicely. If not we might need to make an adjustment or two.


Let me know what you think - thanks for all your work!

rickihastings commented 4 years ago

Hey, no worries at all!

That sounds cool. I've had a look at specs myself I'm a big fan of the ECS pattern. If you need any help on this or anything else moving forward let me know, I'd love to get involved in the project more. I was planning on picking off some of the bugs and possibly looking at adding some new features / documentation to get the project more stable.

pyrossh commented 4 years ago

@rickihastings Wow was thinking about custom components with props like yew and was looking to implement it until I found this. I need an isomorphic html engine/macro with component support for building something cool. Thanks. Now I just need to implement functional components with hooks like react.

rickihastings commented 4 years ago

I tried experimenting with a hooks like pattern in Percy not long ago. While working on this I also came across this https://blog.anp.lol/rust/moxie-intro/ on Reddit. Which is quite nice.

I love hooks in React and think they're a huge improvement on class components. But I think a redux reducer style architecture is more useful and allows sharing state in a much nicer way.

That said, I like Yew as well, but I'm not a huge fan of Elm and I don't like you're forced to use that pattern.

I'm interested to see what an ECS style architecture could produce though.

chinedufn commented 4 years ago

@rickihastings I’m pumped about you being more involved - your work so far has already been great so anything more is a bonus!

I say we proceed like this:

Thoughts on that plan?

rickihastings commented 4 years ago

Hey @chinedufn, that sounds awesome. I've been a bit out of the rust world recently so I'll hopefully try get back into it soon to contribute again!

chinedufn commented 4 years ago

Update: I've started exploring using specs in a web application. Feeling things out right now while working on a website - so I'll see what patterns emerge!

rickihastings commented 4 years ago

Totally forgot about this! Nice, thanks for the update. Looking forward to the outcomes.

chinedufn commented 4 years ago

@rickihastings based on what I'm finding with my specs experimentation this PR should fit in totally fine.

I know you mentioned taking a break from Rust - so I'm happy to take over this PR from you if ya like?

I think it's pretty much good to merge as is

chinedufn commented 4 years ago

Alright made a couple minor tweaks and rebased - this is good to go.

Thanks!

rickihastings commented 4 years ago

Awesome, yeah haven't done any Rust for a while so need to get back into it a little. Changes look good though, thanks for merging!