Skip to content

Commit

Permalink
refactor(antd/next/element): adjust the read priority of Form context
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 21, 2021
1 parent b610168 commit f0c29bb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
22 changes: 22 additions & 0 deletions docs/functions/npm-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Handler } from '@netlify/functions'
import qs from 'querystring'
import axios from 'axios'

const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET',
}

export const handler: Handler = async (event) => {
if (event.httpMethod !== 'GET') {
return { statusCode: 405, body: 'Method Not Allowed' }
}
const params = qs.parse(event.rawQuery)
const results = await axios.get(`https://www.npmjs.com/search?q=${params.q}`)
return {
statusCode: 200,
headers,
body: JSON.stringify(results.data),
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"antd": "^4.0.0",
"chalk": "^2.4.2",
"chokidar": "^2.1.2",
"axios": "^0.23.0",
"querystring": "^0.2.1",
"concurrently": "^4.1.0",
"conventional-commit-types": "^2.2.0",
"cool-path": "^1.0.6",
Expand Down
7 changes: 4 additions & 3 deletions packages/antd/src/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export const Form: React.FC<FormProps> = ({
</FormLayout>
</PreviewText.Placeholder>
)
if (top) return renderContent(top)
if (!form) throw new Error('must pass form instance by createForm')
return <FormProvider form={form}>{renderContent(form)}</FormProvider>
if (form)
return <FormProvider form={form}>{renderContent(form)}</FormProvider>
if (!top) throw new Error('must pass form instance by createForm')
return renderContent(top)
}

Form.defaultProps = {
Expand Down
1 change: 0 additions & 1 deletion packages/element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@vuepress-dumi/vuepress-theme-dumi": "0.3.3",
"@vuepress/plugin-back-to-top": "^1.8.2",
"@vuepress/plugin-medium-zoom": "^1.8.2",
"axios": "^0.21.1",
"codesandbox": "^2.2.3",
"core-js": "^2.4.0",
"element-ui": "latest",
Expand Down
20 changes: 10 additions & 10 deletions packages/element/src/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ export const Form = defineComponent<FormProps>({
)
}

if (top.value) {
return renderContent(top.value)
if (form) {
return h(
FormProvider,
{ props: { form } },
{
default: () => renderContent(form),
}
)
}

if (!form) throw new Error('must pass form instance by createForm')
if (!top.value) throw new Error('must pass form instance by createForm')

return h(
FormProvider,
{ props: { form } },
{
default: () => renderContent(form),
}
)
return renderContent(top.value)
}
},
})
Expand Down
9 changes: 4 additions & 5 deletions packages/next/src/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ export const Form: React.FC<FormProps> = ({
</PreviewText.Placeholder>
)

if (top) return renderContent(top)

if (!form) throw new Error('must pass form instance by createForm')

return <FormProvider form={form}>{renderContent(form)}</FormProvider>
if (form)
return <FormProvider form={form}>{renderContent(form)}</FormProvider>
if (!top) throw new Error('must pass form instance by createForm')
return renderContent(top)
}

Form.defaultProps = {
Expand Down
22 changes: 16 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4524,12 +4524,12 @@ axios@^0.18.1:
follow-redirects "1.5.10"
is-buffer "^2.0.2"

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
axios@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.23.0.tgz#b0fa5d0948a8d1d75e3d5635238b6c4625b05149"
integrity sha512-NmvAE4i0YAv5cKq8zlDoPd1VLKAqX5oLuZKs8xkJa4qi6RGn0uhCYFjWtHHC9EM/MwOwYWOs53W+V0aqEXq1sg==
dependencies:
follow-redirects "^1.10.0"
follow-redirects "^1.14.4"

babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
Expand Down Expand Up @@ -8597,11 +8597,16 @@ follow-redirects@1.5.10:
dependencies:
debug "=3.1.0"

follow-redirects@^1.0.0, follow-redirects@^1.10.0:
follow-redirects@^1.0.0:
version "1.14.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.2.tgz#cecb825047c00f5e66b142f90fed4f515dec789b"
integrity sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==

follow-redirects@^1.14.4:
version "1.14.4"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -16125,6 +16130,11 @@ querystring@0.2.0:
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=

querystring@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd"
integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==

querystringify@^2.1.1:
version "2.2.0"
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
Expand Down

0 comments on commit f0c29bb

Please sign in to comment.