From 2e6ae1fc53f6706f00e6e21f05d429a49827ac08 Mon Sep 17 00:00:00 2001 From: catchonme Date: Fri, 21 Jun 2019 17:31:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9$refs->$ref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/factory.test.tsx | 20 ++++++++++---------- docs/renderers/Definitions.md | 16 ++++++++-------- examples/components/Form/Definitions.jsx | 14 +++++++------- src/factory.tsx | 14 +++++++------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/__tests__/factory.test.tsx b/__tests__/factory.test.tsx index 0fec7a4c..9e86c811 100644 --- a/__tests__/factory.test.tsx +++ b/__tests__/factory.test.tsx @@ -127,7 +127,7 @@ test('factory:definitions', () => { type: 'text', name: 'jack', value: 'refs value', - remark: '通过\\$refs引入的组件' + remark: '通过\\$ref引入的组件' }, bb: { type: 'combo', @@ -143,12 +143,12 @@ test('factory:definitions', () => { { label: 'combo 2', name: 'value', - $refs: 'aa' + $ref: 'aa' }, { name: 'children', label: 'children', - $refs: 'bb' + $ref: 'bb' } ] } @@ -163,12 +163,12 @@ test('factory:definitions', () => { controls: [ { label: 'text2', - $refs: 'aa', + $ref: 'aa', name: 'refs1' }, { label: 'combo', - $refs: 'bb', + $ref: 'bb', name: 'refs2' } ] @@ -190,7 +190,7 @@ test('factory:definitions override', () => { aa: { type: 'text', name: 'jack', - remark: '通过\\$refs引入的组件' + remark: '通过\\$ref引入的组件' }, bb: { type: 'combo', @@ -206,12 +206,12 @@ test('factory:definitions override', () => { { label: 'combo 2', name: 'value', - $refs: 'aa' + $ref: 'aa' }, { name: 'children', label: 'children', - $refs: 'bb' + $ref: 'bb' } ] } @@ -226,12 +226,12 @@ test('factory:definitions override', () => { controls: [ { label: 'text2', - $refs: 'aa', + $ref: 'aa', name: 'refs1' }, { label: 'combo', - $refs: 'bb', + $ref: 'bb', name: 'refs2', type: 'checkboxes', value: 1, diff --git a/docs/renderers/Definitions.md b/docs/renderers/Definitions.md index 85c6d348..4d7235c1 100644 --- a/docs/renderers/Definitions.md +++ b/docs/renderers/Definitions.md @@ -1,6 +1,6 @@ ## Definitions -`Definitions`建立当前页面公共的配置项,在其他组件中可以通过`$refs`来引用当前配置项中的内容 +`Definitions`建立当前页面公共的配置项,在其他组件中可以通过`$ref`来引用当前配置项中的内容 ```schema:height="600" { @@ -9,7 +9,7 @@ "type": "text", "name": "jack", "value": "refs value", - "remark": "通过\\$refs引入的组件" + "remark": "通过\\$ref引入的组件" }, "bb": { "type": "combo", @@ -25,13 +25,13 @@ { "label": "combo 2", "name": "value", - "$refs": "aa", + "$ref": "aa", "remark": "definitions 中可以引用 definitions 中其他的属性" }, { "name": "children", "label": "children", - "$refs": "bb" + "$ref": "bb" } ] } @@ -46,12 +46,12 @@ "controls": [ { "label": "text2", - "$refs": "aa", + "$ref": "aa", "name": "refs1" }, { "label": "combo", - "$refs": "bb", + "$ref": "bb", "name": "refs2" } ] @@ -63,7 +63,7 @@ "controls": [ { "label": "select", - "$refs": "aa", + "$ref": "aa", "name": "select", "type": "select", "value": 1, @@ -81,7 +81,7 @@ }, { "label": "radios", - "$refs": "bb", + "$ref": "bb", "type": "radios", "name": "radios", "value": "Option A", diff --git a/examples/components/Form/Definitions.jsx b/examples/components/Form/Definitions.jsx index fde5e125..2aaeba29 100644 --- a/examples/components/Form/Definitions.jsx +++ b/examples/components/Form/Definitions.jsx @@ -5,7 +5,7 @@ export default { type: 'text', name: 'jack', value: 'refs value', - remark: '通过\\$refs引入的组件' + remark: '通过\\$ref引入的组件' }, bb: { type: 'combo', @@ -21,13 +21,13 @@ export default { { label: 'combo 2', name: 'value', - $refs: 'aa', + $ref: 'aa', remark: 'definitions 中可以引用 definitions 中其他的属性' }, { name: 'children', label: 'children', - $refs: 'bb' + $ref: 'bb' } ] } @@ -42,12 +42,12 @@ export default { controls: [ { label: 'text2', - $refs: 'aa', + $ref: 'aa', name: 'refs1' }, { label: 'combo', - $refs: 'bb', + $ref: 'bb', name: 'refs2' } ] @@ -59,7 +59,7 @@ export default { controls: [ { label: 'select', - $refs: 'aa', + $ref: 'aa', name: 'select', type: 'select', value: 1, @@ -77,7 +77,7 @@ export default { }, { label: 'radios', - $refs: 'bb', + $ref: 'bb', type: 'radios', name: 'radios', value: 'Option A', diff --git a/src/factory.tsx b/src/factory.tsx index 810ddeec..111e3239 100644 --- a/src/factory.tsx +++ b/src/factory.tsx @@ -412,21 +412,21 @@ class SchemaRenderer extends React.Component { let schema = props.schema; let path = props.$path; const rendererResolver = props.env.rendererResolver || resolveRenderer; - if (schema.$refs) { + if (schema.$ref) { schema = { - ...props.resolveDefinitions(schema.$refs), + ...props.resolveDefinitions(schema.$ref), ...schema }; - delete schema.$refs; + delete schema.$ref; path = path.replace(/(?!.*\/).*/, schema.type); } // value 会提前从 control 中获取到,所有需要把control中的属性也补充完整 - if (schema.control && schema.control.$refs) { + if (schema.control && schema.control.$ref) { schema.control = { - ...props.resolveDefinitions(schema.control.$refs), + ...props.resolveDefinitions(schema.control.$ref), ...schema.control } - delete schema.control.$refs; + delete schema.control.$ref; } this.renderer = rendererResolver(path, schema, props); return schema; @@ -477,7 +477,7 @@ class SchemaRenderer extends React.Component { ...rest } = this.props; - if (schema.$refs) { + if (schema.$ref) { schema = this.resolveRenderer(this.props); }