From 8b5efd5c93b711f90593a17d13c9d5dfc3562cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E6=B1=89=E5=8D=87?= <47938757+hansonGong@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:48:04 +0800 Subject: [PATCH 1/3] fix(omi): getTypeValueofProp > getTypeValueOfProp --- packages/omi/src/component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/omi/src/component.ts b/packages/omi/src/component.ts index c5651e121..b7b057e11 100644 --- a/packages/omi/src/component.ts +++ b/packages/omi/src/component.ts @@ -164,8 +164,8 @@ export class Component extends HTMLElement { if (this.constructor.props && this.constructor.props[propsName]) { const prop = this.constructor.props[propsName] if (prop.changed) { - const newTypeValue = this.getTypeValueofProp(propsName, newValue) - const oldTypeValue = this.getTypeValueofProp(propsName, oldValue) + const newTypeValue = this.getTypeValueOfProp(propsName, newValue) + const oldTypeValue = this.getTypeValueOfProp(propsName, oldValue) prop.changed.call(this, newTypeValue, oldTypeValue) } } From 31224efbfb42827eaedaf8416c8edce64ad14f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E6=B1=89=E5=8D=87?= <47938757+hansonGong@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:03:08 +0800 Subject: [PATCH 2/3] chore(omi): propsName > propName --- packages/omi/src/component.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/omi/src/component.ts b/packages/omi/src/component.ts index b7b057e11..761b270f6 100644 --- a/packages/omi/src/component.ts +++ b/packages/omi/src/component.ts @@ -160,12 +160,12 @@ export class Component 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) } } From c6505ecb0ad22c8799772f705211fe4260021648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E6=B1=89=E5=8D=87?= <47938757+hansonGong@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:30:29 +0800 Subject: [PATCH 3/3] feat(omi): attributeChangedCallback --- packages/omi/test/attrs-to-props.test.jsx | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/omi/test/attrs-to-props.test.jsx b/packages/omi/test/attrs-to-props.test.jsx index b7b299621..8b630bef2 100644 --- a/packages/omi/test/attrs-to-props.test.jsx +++ b/packages/omi/test/attrs-to-props.test.jsx @@ -375,4 +375,33 @@ describe('attrs to props', () => { expect(parentElement.firstChild.shadowRoot.innerHTML).toBe('
18
') }) + 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
{props.myAge}
+ } + } + + 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) + }) + })