Skip to content

Commit

Permalink
modify snabbdom to allow str obj
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Aug 17, 2021
1 parent b32b00d commit c3fc75a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion opal/snabberb/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def h(element, props = {}, children = nil)
props_is_hash = props.is_a?(Hash)
children = props if !children && !props_is_hash
props = {} unless props_is_hash
children = children.to_n if children.is_a?(String)
`snabbdom.h(#{element}, #{Native.convert(props)}, #{children})`
end
end
Expand Down
6 changes: 3 additions & 3 deletions opal/vendor/snabbdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ function h(sel, b, c) {
if (is.array(c)) {
children = c;
} else if (is.primitive(c)) {
text = c;
text = c.toString();
} else if (c && c.sel) {
children = [c];
}
} else if (b !== undefined && b !== null) {
if (is.array(b)) {
children = b;
} else if (is.primitive(b)) {
text = b;
text = b.toString();
} else if (b && b.sel) {
children = [b];
} else {
Expand Down Expand Up @@ -582,7 +582,7 @@ const array = Array.isArray;
exports.array = array;

function primitive(s) {
return typeof s === "string" || typeof s === "number";
return typeof s === "string" || typeof s === "number" || s instanceof String;
}

},{}],6:[function(require,module,exports){
Expand Down
2 changes: 2 additions & 0 deletions spec/snabberb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def render
it 'renders text' do
expect(elements_to_html("h('div', 'hello')")).to eq('<div>hello</div>')
expect(elements_to_html("h('div', 'a' + '')")).to eq('<div>a</div>')
expect(elements_to_html("h('div', ['a'])")).to eq('<div>a</div>')
expect(elements_to_html("h('div', ['a', 'b' + ''])")).to eq('<div>ab</div>')
expect(elements_to_html("h('div', 1)")).to eq('<div>1</div>')
expect(elements_to_html("h('div')")).to eq('<div></div>')
expect(elements_to_html("h('br')")).to eq('<br>')
Expand Down

0 comments on commit c3fc75a

Please sign in to comment.