john-hu / react-designpane

Apache License 2.0
1 stars 0 forks source link

Component Tree? #1

Open john-hu opened 5 years ago

john-hu commented 5 years ago

We can use the React Node and React Children as our component tree. But it is not easy to traverse back and forth among the tree. The most inconvenient parts are:

  1. It is hard to find the container of a node. When we try to move a node to another container. We don't know where we should remove the node from.

  2. It is impossible to keep the original React Node when we try to re-order its children. If we change any property or the children, we should use React.createElement or React.cloneElement to do it. Once we use it, the original React Node is changed.

The possible solution is to break one promise (solution 1):

We always keep the original node we get to tell users the change of layout.

Another alternative is to introduce an intermediate data format, like the Component/Container class of Java (solution 2).


Pros of Solution 1:

Cons of Solution 1:


Pros of Solution 2

Cons of Solution 2

john-hu commented 5 years ago

I will try to use Solution 1 and create an internal controller to handle the cache, Hierarchy Builder. We will change the interface of onLayoutChange from difference to the ReactChildren component.

john-hu commented 5 years ago

~TODO: we should handle the movement at the same container~

john-hu commented 5 years ago

TODO: the key field of the generated ReactNode is already filled ?!.... For example: a node without key is filled with “.0”, a node with “div” in key is filled with “.$div”. This may be caused by the usage of createElement with apply.

john-hu commented 5 years ago

TODO: We will try to use HierarchyBuilder as the bridge to share the information between DesignPane and ComponentTree. The user can layout ComponentTree and DesignPane by their thought.