Skip to content

Commit

Permalink
fix: 标记部分 class 无副作用
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Dec 27, 2024
1 parent e414887 commit 84b17eb
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 253 deletions.
15 changes: 9 additions & 6 deletions packages/uni-app-plus/src/x/components/button/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ export const buttonProps = {
}
// 这里是从 x-dom 的 global 里读取的

export class UniButtonElement extends UniTextElementImpl {
// constructor(data: INodeData) {
// super()
// // super(data)
// }
}
export const UniButtonElement = /* @__PURE__ */ (() =>
class extends UniTextElementImpl {
// constructor(data: INodeData) {
// super()
// // super(data)
// }
})()

export type UniButtonElement = InstanceType<typeof UniButtonElement>

export const hoverStyles = new Map<string, Map<string, any | null>>([
[
Expand Down
86 changes: 48 additions & 38 deletions packages/uni-app-plus/src/x/components/checkbox-group/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,51 @@ export interface CheckboxInfo {
setCheckboxChecked: (checked: boolean) => void
}

export class UniCheckboxGroupElement extends UniFormControlElement<string[]> {
_initialValue: string[] = []
export const UniCheckboxGroupElement = /* @__PURE__ */ (() =>
class extends UniFormControlElement<string[]> {
_initialValue: string[] = []

constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}

override tagName = 'CHECKBOX-GROUP'
override nodeName = this.tagName
override tagName = 'CHECKBOX-GROUP'
override nodeName = this.tagName

override get value(): string[] {
return this._getValue()
}
override get value(): string[] {
return this._getValue()
}

override set value(value: string[]) {
this._setValue(value)
}
override set value(value: string[]) {
this._setValue(value)
}

override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
}
return super.getAnyAttribute(key)
}
return super.getAnyAttribute(key)
}

// 这个会被重写
_getAttribute = (key: string): string | null => {
return null
}
// 这个会被重写
_getAttribute = (key: string): string | null => {
return null
}

override reset() {
this.value = this._initialValue.slice(0)
}
override reset() {
this.value = this._initialValue.slice(0)
}

_getValue = (): string[] => {
return this._initialValue
}
_setValue = (value: string[]) => {}
}
_getValue = (): string[] => {
return this._initialValue
}
_setValue = (value: string[]) => {}
})()

export type UniCheckboxGroupElement = InstanceType<
typeof UniCheckboxGroupElement
>

// export const checkboxGroupProps = {}
class UniCheckboxGroupChangeEventDetail {
Expand All @@ -64,10 +69,15 @@ class UniCheckboxGroupChangeEventDetail {
this.value = value
}
}
export class UniCheckboxGroupChangeEvent extends UniCustomEvent<UniCheckboxGroupChangeEventDetail> {
constructor(value: string[]) {
super('change', {
detail: new UniCheckboxGroupChangeEventDetail(value),
})
}
}
export const UniCheckboxGroupChangeEvent = /* @__PURE__ */ (() =>
class extends UniCustomEvent<UniCheckboxGroupChangeEventDetail> {
constructor(value: string[]) {
super('change', {
detail: new UniCheckboxGroupChangeEventDetail(value),
})
}
})()

export type UniCheckboxGroupChangeEvent = InstanceType<
typeof UniCheckboxGroupChangeEvent
>
35 changes: 19 additions & 16 deletions packages/uni-app-plus/src/x/components/checkbox/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
export const CHECKBOX_NAME = 'Checkbox'
export const CHECKBOX_ROOT_ELEMENT = 'uni-checkbox-element'

export class UniCheckboxElement extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}
export const UniCheckboxElement = /* @__PURE__ */ (() =>
class extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}

override tagName = 'CHECKBOX'
override nodeName = this.tagName
override tagName = 'CHECKBOX'
override nodeName = this.tagName

override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
}
return super.getAnyAttribute(key)
}
return super.getAnyAttribute(key)
}

_getAttribute = (key: string): string | null => {
return null
}
}
_getAttribute = (key: string): string | null => {
return null
}
})()

export type UniCheckboxElement = InstanceType<typeof UniCheckboxElement>

// UniElementImpl

Expand Down
75 changes: 42 additions & 33 deletions packages/uni-app-plus/src/x/components/form/form.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
/// <reference types="@dcloudio/uni-app-x/types/native-global" />
import { defineBuiltInComponent } from '@dcloudio/uni-components'
import {
onMounted,
ComponentInternalInstance,
type ComponentInternalInstance,
type Ref,
type VNode,
getCurrentInstance,
onMounted,
ref,
Ref,
VNode,
} from 'vue'

export class UniFormElement extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}
export const UniFormElement = /* @__PURE__ */ (() =>
class extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}

// override getAttribute(key: string): string | null {
// const value = this._getAttribute(key)
// if (value != null) {
// return value
// }
// return super.getAttribute(key)
// }
// override getAttribute(key: string): string | null {
// const value = this._getAttribute(key)
// if (value != null) {
// return value
// }
// return super.getAttribute(key)
// }

_getAttribute = (key: string): string | null => {
return null
}
}
_getAttribute = (key: string): string | null => {
return null
}
})()

export type UniFormElement = InstanceType<typeof UniFormElement>

class UniFormSubmitEventDetail {
value = {}
Expand All @@ -36,21 +39,27 @@ class UniFormSubmitEventDetail {

class UniFormResetEventDetail {}

export class UniFormSubmitEvent extends CustomEvent<UniFormSubmitEventDetail> {
constructor(value: any) {
super('change', {
detail: new UniFormSubmitEventDetail(value),
} as CustomEventOptions<UniFormSubmitEventDetail>)
}
}
export const UniFormSubmitEvent = /* @__PURE__ */ (() =>
class extends CustomEvent<UniFormSubmitEventDetail> {
constructor(value: any) {
super('change', {
detail: new UniFormSubmitEventDetail(value),
} as CustomEventOptions<UniFormSubmitEventDetail>)
}
})()

export class UniFormResetEvent extends CustomEvent<UniFormResetEventDetail> {
constructor() {
super('change', {
detail: new UniFormResetEventDetail(),
} as CustomEventOptions<UniFormResetEventDetail>)
}
}
export type UniFormSubmitEvent = InstanceType<typeof UniFormSubmitEvent>

export const UniFormResetEvent = /* @__PURE__ */ (() =>
class extends CustomEvent<UniFormResetEventDetail> {
constructor() {
super('change', {
detail: new UniFormResetEventDetail(),
} as CustomEventOptions<UniFormResetEventDetail>)
}
})()

export type UniFormResetEvent = InstanceType<typeof UniFormResetEvent>

export default /*#__PURE__*/ defineBuiltInComponent({
name: 'Form',
Expand Down
36 changes: 20 additions & 16 deletions packages/uni-app-plus/src/x/components/navigator/model.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
export class UniNavigatorElement extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}
export const UniNavigatorElement = /* @__PURE__ */ (() =>
class extends UniElementImpl {
constructor(data: INodeData, pageNode: PageNode) {
super(data, pageNode)
}

override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
override getAnyAttribute(key: string): string {
const value = this._getAttribute(key)
if (value != null) {
return value
}
return super.getAnyAttribute(key)
}
return super.getAnyAttribute(key)
}

override tagName = 'NAVIGATOR'
override nodeName = this.tagName
override tagName = 'NAVIGATOR'
override nodeName = this.tagName

_getAttribute = (key: string): string | null => {
return null
}
})()

export type UniNavigatorElement = InstanceType<typeof UniNavigatorElement>

_getAttribute = (key: string): string | null => {
return null
}
}
export const navigatorProps = {
url: {
type: String,
Expand Down
Loading

0 comments on commit 84b17eb

Please sign in to comment.