Gurigraphics / DOMinus.js

DOMinus.js is a reactive data binding library that turn HTML irrelevant.
4 stars 1 forks source link

2 questions #1

Closed thipages closed 5 years ago

thipages commented 5 years ago

Hi, first, thanks for your code. I have two questions (case 1, case 2 within the sample code) .

  1. Case 1 if the "html" property is omitted, the inputbox will not be shawn (same if html:""). Why?
  2. Case 2 if value property is set (eg "HGddG"), the input box DO show the initial value Instead if the "value" property is defined as a property of of the attrs object the input box DO NOT show the initial value. Why it is not reverse case?
        HTML["mydiv"] = {
            type: "div",
            attrs: { id: "mydiv" },
            html: "mydiv_content"
        };
        HTML["mydiv_content"] = [{
            type: "input",
            attrs: {id: "mydiv_content", type:"text"},
            value:"HGddG", // case 2
            html:" " // case 1
        }];
        DOM.add("mydiv", "#app");
Gurigraphics commented 5 years ago

Hi, I forgot to correct this exceptions. First I had done so:

h("ul", { id:"firstID" }, 
    h("li", { id:"secondID" }, "htmlText" )
)

But objects is better to maintaining and expanding complex code. It's also better than import html templates.

Case 1 For now, without the html use a space:

html: " " 

Case 2 Element inside other use format array - without the tag attrs.

HTML["mydiv_content"] = [
 { type:"input", id: "mydiv_content", value:"HGddG", html: " " }
]

Example:

HTML["mydiv"] = {
  type: "div",
  attrs: { id: "mydiv" },
  html: "mydiv_content"
};

HTML["mydiv_content"] = [
 { type:"input", id: "mydiv_content_input", value:"HGddG", html: " " }
]

DOM.add("mydiv", "#app");

// HTML.mydiv_content[0].id = "newID"
// HTML.mydiv_content[0].value = "newValue"
// DOM.remove("mydiv_content_input")

Sandbox: https://playcode.io/180373

thipages commented 5 years ago

Hi, thanks for sharing the shortcuts with the h() function, it can be useful. for case 1, the workaround is clear and ok. for case 2, I undersrand now. However how to add type="text" for an input in a child declaration?

HTML["mydiv_content"] = [
 { type:"input", id: "mydiv_content", value:"HGddG", html: " " }
]
Gurigraphics commented 5 years ago

Good question. I did not think of that. /o\ I need to change this to "kind: input"

For now, you can use this:

HTML["mydiv_content"] = [
{ type:"div", id: "mydiv_content_input", html: "<input type='text' value='HGddG'/>" }
]
thipages commented 5 years ago

"kind" itself seems to be taken : w3schools.com/tags/att_kind why not using "tag" instead ?

Gurigraphics commented 5 years ago

Good idea.

Other problem. I need to find a list of all simple tags. simple: <input/> double: <div></div>

I used only: types: [ "input", "img", "area", "source", "embed" ],

Missed this <track/>

If I do not put the value in this array, stays: <track></track> And pollutes HTML

I found this one, it must be complete https://developer.mozilla.org/en-US/docs/Glossary/Empty_element

types: ["area","base","br","col","embed","hr","img","input",
"keygen","link","meta","param","source","track","wbr" ],
thipages commented 5 years ago

the list is ok

Gurigraphics commented 5 years ago

Updated to 1.0.0 https://github.com/Gurigraphics/DOMinus.js/issues/2

thipages commented 5 years ago

Tested. Ok