Skip to content

Commit

Permalink
Merge pull request #930 from hansonGong/fix/api-name
Browse files Browse the repository at this point in the history
fix(omi): getTypeValueofProp > getTypeValueOfProp
  • Loading branch information
dntzhang authored Nov 23, 2024
2 parents 441b041 + c6505ec commit dd4a6bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/omi/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export class Component<State = any> extends HTMLElement {
}

attributeChangedCallback(name, oldValue, newValue) {
const propsName = camelCase(name)
if (this.constructor.props && this.constructor.props[propsName]) {
const prop = this.constructor.props[propsName]
const propName = camelCase(name)
if (this.constructor.props && this.constructor.props[propName]) {
const prop = this.constructor.props[propName]
if (prop.changed) {
const newTypeValue = this.getTypeValueofProp(propsName, newValue)
const oldTypeValue = this.getTypeValueofProp(propsName, oldValue)
const newTypeValue = this.getTypeValueOfProp(propName, newValue)
const oldTypeValue = this.getTypeValueOfProp(propName, oldValue)
prop.changed.call(this, newTypeValue, oldTypeValue)
}
}
Expand Down
29 changes: 29 additions & 0 deletions packages/omi/test/attrs-to-props.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,33 @@ describe('attrs to props', () => {
expect(parentElement.firstChild.shadowRoot.innerHTML).toBe('<div>18</div>')
})

it('updateProps2', async () => {
var valA, valB
class Ele extends Component {
static props = {
myAge: {
type: Number,
changed(newVal, oldVal) {
valA = newVal
valB = oldVal
}
},
}

render(props) {
return <div>{props.myAge}</div>
}
}

const node = genNode()
define(node.name, Ele)
const el = document.createElement(node.name)
parentElement.appendChild(el)
el.setProp('my-age', 18)
el.setProp('my-age', 19)

expect(valA).toBe(19)
expect(valB).toBe(18)
})

})

0 comments on commit dd4a6bb

Please sign in to comment.