Skip to content

Commit

Permalink
Merge pull request #211 from wechat-miniprogram/fix-template-default-…
Browse files Browse the repository at this point in the history
…update-path-tree

fix: default update path tree on template data (#210)
  • Loading branch information
LastLeaf authored Oct 31, 2024
2 parents f17a552 + 34c3b55 commit ff37da4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions glass-easel-template-compiler/src/proc_gen/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ impl Element {
Value::Static { value, .. } => w.expr_stmt(|w| {
write!(
w,
"if({}&&{}){}(R,C,{},undefined).C(C,T,E,B,F,S,J)",
"if({}&&{}){}(R,C,{},Object.create(null)).C(C,T,E,B,F,S,J)",
var_key,
var_target,
var_target,
Expand All @@ -1012,7 +1012,7 @@ impl Element {
p.value_expr(w)?;
write!(w, ",K||(U?")?;
p.lvalue_state_expr(w, scopes, true)?;
write!(w, ":undefined)).C(C,T,E,B,F,S,J)")?;
write!(w, ":Object.create(null))).C(C,T,E,B,F,S,J)")?;
Ok(())
})
}
Expand Down
26 changes: 26 additions & 0 deletions glass-easel/tests/tmpl/structure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,32 @@ const testCases = (testBackend: glassEasel.GeneralBackendContext) => {
matchElementWithDom(elem)
})

test('undefined template-data', () => {
const def = glassEasel
.registerElement({
template: tmpl(`
<template name="child">
<span>{{ a }}</span>
</template>
<div>
<template is="child" />
<template is="child" data="{{ b }}" />
</div>
`),
data: {
a: 123,
b: 789,
},
})
.general()
const elem = glassEasel.Component.createWithContext('root', def, testBackend)
expect(domHtml(elem)).toBe('<div><span></span><span></span></div>')
matchElementWithDom(elem)
elem.setData({ a: 456 })
expect(domHtml(elem)).toBe('<div><span></span><span></span></div>')
matchElementWithDom(elem)
})

test('cascaded template', () => {
const def = glassEasel
.registerElement({
Expand Down

0 comments on commit ff37da4

Please sign in to comment.