Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wx:key #1462

Merged
merged 9 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import directiveHelperMixin from './directiveHelperMixin.ios'
export default directiveHelperMixin
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { warn, type } from '@mpxjs/utils'
export default function directiveHelperMixin () {
return {
methods: {
__getWxKey (item, key) {
const value = key === '*this' ? item : item[key]
if (typeof value === 'string' || typeof value === 'number') {
return value
} else {
warn(`wx:key's value should return a string or a number, received: ${type(value)}`, this.__mpxProxy.options.mpxFileResource)
}
}
}
}
}
2 changes: 2 additions & 0 deletions packages/core/src/platform/builtInMixins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import componentGenericsMixin from './componentGenericsMixin'
import getTabBarMixin from './getTabBarMixin'
import pageRouteMixin from './pageRouteMixin'
import styleHelperMixin from './styleHelperMixin'
import directiveHelperMixin from './directiveHelperMixin'
import { isReact } from '@mpxjs/utils'

export default function getBuiltInMixins (options, type) {
let bulitInMixins
if (isReact) {
bulitInMixins = [
proxyEventMixin(),
directiveHelperMixin(),
styleHelperMixin()
]
} else if (__mpx_mode__ === 'web') {
Expand Down
7 changes: 7 additions & 0 deletions packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,13 @@ function postProcessFor (el) {

function postProcessForReact (el) {
if (el.for) {
if (el.for.key) {
addExp(el, `this.__getWxKey(${el.for.item}, '${el.for.key}')`, false, 'key')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

el.for.item||'item'

addAttrs(el, [{
name: 'key',
value: el.for.key
}])
}
popForScopes()
}
}
Expand Down
Loading