zaceno / hyperapp-nestable

Embed apps in other apps, as if they were components
MIT License
40 stars 8 forks source link

Central state integration? #4

Closed marcelklehr closed 6 years ago

marcelklehr commented 6 years ago

Hey @zaceno !

This is what I've been looking for. Awesome stuff! What I've been wondering is whether it would be possible to integrate the sub-app's state into the state of the main app? This would allow writing components as apps that are much more encapsulated than the normal components which need to declare their state and actions on the main app, requiring some central bookkeeping, afaict.

tino commented 6 years ago

Yeah, would like this as well! Now hyperapp/router doesn't work with nestable components šŸ™ƒ

zaceno commented 6 years ago

@marcelklehr @tino

šŸ¤” Hmm... Well, the use-case for nestable is mainly when you have a component that needs some local state that the rest of the app doesn't care about (like form validation, for example -- the rest of the app only cares about a valid form submission). Therefore, it doesn't make much sense to me to integrate nestables' state into main-state. The whole reason I wrote it was to keep state out of the main šŸ˜…

It sounds to me (although I may be mistaken, ofc) that maybe what you're looking for is a way to write encapsulated modules containing state, actions, and views (essentially standalone apps), in such a way that you can compose the modules (not just the view, but state and actions also) together into a larger app.

If that's what you're after, perhaps this post I wrote could give you some ideas:

https://zaceno.github.io/hypercraft/post/modular-apps/

zaceno commented 6 years ago

@tino fwiw the router is kind of tricky, and not very robust in my experience. Even if you're not using nestable, there are issues and gotchas to be aware of. I would try to keep things as vanilla as possible if I were using hyperapp/router

zaceno commented 6 years ago

@marcelklehr I'm going to close here for now, since I'm not sure what it is you're proposing exactly. Hopefully the link I shared above can provide you a path forward. Otherwise, please reopen if you have like a pseudo-code example to clarify what you need.

BTW, I realize I left this open 3 weeks before answering! My sincere apologies! I just didn't notice it until a couple of days ago.

tino commented 6 years ago

šŸ™ŒšŸ¼ For that post. It is indeed what I was looking for but couldnā€™t find in everything going on around hyperapp. Thatā€™s also the reason I got to use nestable.

To be fair,

the use-case for nestable is mainly when you have a component that needs some local state that the rest of the app doesn't care about Is what I sttempted: one ā€œpageā€ doesnā€™t need to know about another page. But it does need to be able to navigate somewhere else ;)

And when we come into ā€œlooselyā€ coupled land, Iā€™m not sure it matters/makes sense to have a single state, as you wouldnā€™t want to rely on things innp the global state anyway as thatā€™s tight coupling.