Skip to content

Commit

Permalink
fixed: evaluate expressions in custom native web components
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Aug 31, 2020
1 parent d60e1ec commit 73d6767
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/bindings/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ function extendParentScope(attributes, scope, parentScope) {

// this function is only meant to fix an edge case
// https://github.com/riot/riot/issues/2842
const getRealParent = (scope, parentScope) => parentScope ?
parentScope === scope ? scope[PARENT_KEY_SYMBOL] : parentScope
: undefined
const getRealParent = (scope, parentScope) => scope[PARENT_KEY_SYMBOL] || parentScope

export const SlotBinding = Object.seal({
// dynamic binding properties
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function slotBindings(slots) {
*/
function slotsToMarkup(slots) {
return slots.reduce((acc, slot) => {
return `${acc}<slot name="${slot.id}">${slot.html}</slot>`
return acc + slot.html
}, '')
}

Expand Down
19 changes: 13 additions & 6 deletions test/bindings/tag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ describe('tag bindings', () => {
},
slots: [{
'id': 'main',
'html': '<p>hello</p>',
'bindings': []
'html': '<p expr2> </p>',
'bindings': [{
selector: '[expr2]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: scope => scope.text
}]
}]
}],
attributes: [{
evaluate: scope => scope.class,
Expand All @@ -60,16 +67,16 @@ describe('tag bindings', () => {
'name': 'main',
'redundantAttribute': 'expr1',
'selector': '[expr1]'
}]).mount(target, {class: 'hello'})
}]).mount(target, {class: 'hello', text: 'hello'})

const b = target.querySelector('b')
const slot = target.querySelector('slot')
const p = target.querySelector('p')

expect(slot).to.be.ok
expect(b).to.be.ok
expect(p).to.be.ok

expect(b.getAttribute('class')).to.be.equal('hello')
expect(slot.getAttribute('name')).to.be.equal('main')
expect(p.innerHTML).to.be.equal('hello')

el.unmount()
})
Expand Down

0 comments on commit 73d6767

Please sign in to comment.