intercellular / cell

A self-driving web app framework
https://www.celljs.org
MIT License
1.5k stars 94 forks source link

Possition of the $cell #14

Closed fprijate closed 7 years ago

fprijate commented 7 years ago

It would be nice if I could specify that $cell :

  1. replaces existing element
  2. is inserted as first child of existing element
  3. is inserted as a last child of existing element
  4. existing element is inserted into it as a first child.
  5. existing element is inserted into it as a last child

Maybe by extending $cell values:

var bla = {
   $cell: v,  
   $type:  "div",
   id: "div1",
   . . .
}

where v can be


  v=true      //   backward compatible
  v="R"       //    replaces div1 element
  v="CF"     //    is inserted as first child of div1 element
  v="CL"     //   is inserted as a last child of div1 element
  v="PF"     //   div1 element is inserted into it as a first child.
  v="PL"     //   div1 element is inserted into it as a last child 

It would be very useful when inserting some new content into existing static html pages.

gliechtenstein commented 7 years ago

Thanks for the idea, I can definitely see where you're coming from.

If you're thinking about using cell with an existing DOM, I think you can easily achieve what you're looking for by using jQuery (via its appendTo, insertAfter, etc. methods) or even native DOM APIs like insertBefore, etc.) since Cell creates native HTML nodes. (If you're plugging Cell into an existing website, you're probably using jQuery anyway, and even if you're not using jQuery you can use vanilla javascript to move them around easily)

Since Cell's design goal is to be as minimal and abstract as possible, and since these features can be achieved with other means I don't think we need to implement this feature. I'll close this for now, but please feel free to reopen or leave a comment for further discussion. Thanks!

fprijate commented 7 years ago

Thanks for your answer

Thanks for the idea, I can definitely see where you're coming from.

No. My primary intention is not to use cell as tool for minor modifications of existing HTML. I have following in my mind. Server sends me JSON and Cell renders it into existing DOM , which was previously rendered by cell. In this case we should have factory method to do this. Byproduct of this is also possibility of inserting cell's into existing static HTML. Both insertions should be possible in previously discussed positions.

Also it would be nice if somebody (or group of us) make a converter from static HTML to cell's JSON.

devsnek commented 7 years ago

@fprijate https://gist.github.com/devsnek/f7c88b2d7f2856da8004b1033511a2d7