@lovelope/create-factory
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -6,2 +6,6 @@ # Change Log | ||
## [0.1.1](https://github.com/lovelope/quark-components/compare/@lovelope/create-factory@0.1.0...@lovelope/create-factory@0.1.1) (2019-08-09) | ||
**Note:** Version bump only for package @lovelope/create-factory | ||
# 0.1.0 (2019-08-09) | ||
@@ -8,0 +12,0 @@ |
{ | ||
"name": "@lovelope/create-factory", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Lightweight higher order components for edit page or detail page.", | ||
@@ -55,3 +55,4 @@ "keywords": [ | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
}, | ||
"gitHead": "e275dd98c71239c7a4224dd8b97867a254b57b92" | ||
} |
@@ -1,11 +0,61 @@ | ||
# `create-factory` | ||
# `@lovelope/create-factory` | ||
> TODO: description | ||
`CreateFactory` is a high-level component used to manage editing pages and details pages; it is mainly responsible for data pulling and updating. | ||
## Usage | ||
[English](./README.md) | ||
[中文](./README.zh-CN.md) | ||
## 安装 | ||
```bash | ||
npm i -S @lovelope/create-factory | ||
# OR | ||
yarn add -S @lovelope/create-factory | ||
``` | ||
const createFactory = require('create-factory'); | ||
// TODO: DEMONSTRATE API | ||
## 使用 | ||
```jsx | ||
import CreateFactory from '@lovelope/create-factory'; | ||
import React from 'react'; | ||
import { Form } from 'antd'; | ||
import { getUserInfo, putUserInfo } from './services'; | ||
const FormItem = Form.Item; | ||
// this page's path is /user/edit/:userId | ||
@CreateFactory({ | ||
key: 'userId', | ||
getAction: getUserInfo, | ||
putAction: putUserInfo, | ||
}) | ||
class Email extends React.Component { | ||
render() { | ||
const { | ||
form: { getFieldDecorator }, | ||
} = this.props; | ||
return ( | ||
<Form> | ||
<FormItem label="username"> | ||
{getFieldDecorator('name')(<Input />)} | ||
</FormItem> | ||
<FormItem label="Eamil"> | ||
{getFieldDecorator('email')(<Input />)} | ||
</FormItem> | ||
</Form> | ||
); | ||
} | ||
} | ||
``` | ||
## Options | ||
| Property | Description | type | required | default | | ||
| ---------------- | -------------------------------------------------------------------------------------------------- | -------------- | -------- | -------- | | ||
| key | ID value defined in routing URL | string, number | false | 'id' | | ||
| getAction | The function that pulls the form data when it is initialized | () => promise | false | -- | | ||
| putAction | Submit the function to be called after editing the form | () => promise | false | -- | | ||
| postAction | The function to be called when adding a new form | promise | false | -- | | ||
| mapPropsToFields | The formatting function of the data that getAction is filled in before the form item is filled in. | function | false | () => {} | | ||
| initialValues | Form default values | object | false | {} | |
30763
11
62