Skip to content

Commit

Permalink
Merge pull request #102 from achou11/69/set-map-weakmap-props
Browse files Browse the repository at this point in the history
add support for passing Map, Set, and WeakMap instances as props
  • Loading branch information
chicoxyzzy authored Jan 12, 2023
2 parents e340536 + de7428a commit e84d21e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export class Tonic extends window.HTMLElement {
return this._prop(o)
}
case '[object Object]':
case '[object Function]': return this._prop(o)
case '[object Function]':
case '[object Set]':
case '[object Map]':
case '[object WeakMap]': return this._prop(o)
case '[object NamedNodeMap]':
return this._prop(Tonic._normalizeAttrs(o))
case '[object Number]': return `${o}__float`
Expand Down
8 changes: 7 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ test('pass props', async t => {
id="y"
data=${test}
number=${42.42}
fn=${() => 'hello, world'}>
fn=${() => 'hello, world'}
set=${new Set(['foo'])}
map=${new Map([['bar', 'bar']])}
weakmap=${new WeakMap([[document, 'baz']])}>
</component-b-b>
`
}
Expand All @@ -256,6 +259,9 @@ test('pass props', async t => {
const props = bb.props
t.equal(props.fn(), 'hello, world', 'passed a function')
t.equal(props.number, 42.42, 'float parsed properly')
t.equal(props.set.has('foo'), true, 'set parsed properly')
t.equal(props.map.get('bar'), 'bar', 'map parsed properly')
t.equal(props.weakmap.get(document), 'baz', 'weak map parsed properly')
}

const div1 = document.getElementsByTagName('div')[0]
Expand Down

0 comments on commit e84d21e

Please sign in to comment.