Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat: 支持在�所有�平台基础组件上使用平台前缀属性 (#1412)
Browse files Browse the repository at this point in the history
* feat: 提升平台前缀属性权重

* perf: 优化 propsAlias

* test: platform prop
  • Loading branch information
noyobo committed Dec 4, 2020
1 parent 0f87073 commit d6e9072
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/remax-runtime/src/__tests__/propsAlias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@ describe('props alias', () => {
it('transform platform props', () => {
expect(getAlias('ali-prop', 'any')).toBe('prop');
});

it('transform platform props priority boost', () => {
expect(
propsAlias(
{
'ali-type': 'foo',
type: 'bar',
},
'any'
)
).toEqual({ type: 'foo' });
});
});
13 changes: 12 additions & 1 deletion packages/remax-runtime/src/propsAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@ export default function propsAlias(props: GenericProps, type: string) {
return props;
}

const prefix = `${RuntimeOptions.get('platform')}-`;

const aliasProps: GenericProps = {};

for (const prop in props) {
aliasProps[getAlias(prop, type)] = getValue(prop, props[prop]);
// 平台前缀属性优先级提升
// @see https://github.com/remaxjs/remax/issues/1409
const hasPrefix = prop.startsWith(prefix);
const key = getAlias(prop, type);
const value = getValue(prop, props[prop]);
if (hasPrefix) {
aliasProps[key] = value;
} else {
aliasProps[key] = aliasProps[key] || value;
}
}

return aliasProps;
Expand Down

1 comment on commit d6e9072

@vercel
Copy link

@vercel vercel bot commented on d6e9072 Dec 4, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.