theplant / containers

Better structures for building web applications
1 stars 0 forks source link

Reload nested containers #16

Closed sunfmin closed 7 years ago

bodhi commented 7 years ago

This really needs an explanation of how:

  1. it works when rendering: since containers are
  2. how it identifies containers to reload

When I wrote the original version, I avoided nested reloading intentionally, since it will very easily get hard to understand what's going on. For example, if a reloadable container A nests another reloadable container B, what happens? Do you render A+B and then replace A in the DOM, then also replace B in the newly replaced A?

sunfmin commented 7 years ago

I am planning to ditch the javascript code, and provide explanation of how the server part of reload works.

https://github.com/theplant/containers/tree/doc#reloading-certain-containers-of-a-page-partially

Basically, you pass in a event name, It will render those container html and give them back to you as a json. How you replace the html page, is in your javascript hand. Normally it is enough to only replace parent container.

By using it in Aigle, we found that without nested container, we can't build a real page. it will end up every page contains Header, Body, Footer container...

sunfmin commented 7 years ago

I find event is quite difficult to understand. So I change it to tags, you can tag containers in a page. And then you can fetch those containers by tag name without other containers.

bodhi commented 7 years ago

Basically, you pass in a event name, It will render those container html and give them back to you as a json.

My question is that there will be containers where you don't know the content of the container until you render it. And if the reloadable content is inside the top-level container, how do you "extract" only the part that needed to be reloaded:

A
- B
  - B1 (reloadable)
  - B2
- C
- D
  - D1
  - D2 (reloadable)

You can't get to B1 or D2 without rendering B or D? And then how do you extract B1 and ignore B2 or any other content from B?

Or have you introduced a pattern for "processing" containers without rendering them, to build up the tree, and then only render specific sub-branches?

I haven't looked too closely at the code, when I saw Reflect I gave up :trollface:

bodhi commented 7 years ago

My question is that there will be containers where you don't know the content of the container until you render it.

Of course, "this type of container cannot have reloadable containers nested inside" is a reasonable constraint to have.

sunfmin commented 7 years ago

You can't get to B1 or D2 without rendering B or D?

You can

bodhi commented 7 years ago

You can't get to B1 or D2 without rendering B or D?

You can

How? B is just something that implements Render(*http.Request) (string, error), no?

sunfmin commented 7 years ago

Call me.

sunfmin commented 7 years ago

B is something implements Render AND have a struct field reference to B1, So with reflect, I can get B1 out, and render it.

bodhi commented 7 years ago

B is something implements be AND have a struct field reference to B1, So with reflect, I can get B1 out, and render it.

Ok, that's the missing piece for me. You've added a new constraint on reloadable containers, that there is a way to get child containers out without calling Render. That's fine, but consider doing it via an interface, rather than reflection?

Actually, since your team is the only one using containers at the moment, do it in the easiest way for your project ;)

sunfmin commented 7 years ago

BTW, the doc for reloading partially:

https://github.com/theplant/containers/tree/doc#fetch-certain-containers-of-a-page-partially