Skip to content

Commit

Permalink
chore(project): release v0.1.15 (#94)
Browse files Browse the repository at this point in the history
* fix(@uform/core): fix #84 #91
  • Loading branch information
janryWang authored Jun 4, 2019
1 parent d29a32f commit bc3125d
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 40 deletions.
4 changes: 2 additions & 2 deletions packages/antd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/antd",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand All @@ -21,7 +21,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/react": "0.1.14",
"@uform/react": "0.1.15",
"@uform/utils": "0.1.8",
"classnames": "^2.2.6",
"moveto": "^1.7.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/builder-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/builder-next",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib/index.js",
"repository": {
Expand All @@ -21,7 +21,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/builder": "0.1.14"
"@uform/builder": "0.1.15"
},
"devDependencies": {
"@alifd/next": "^1.13.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/builder",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib/index.js",
"repository": {
Expand All @@ -24,7 +24,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/react": "0.1.14",
"@uform/react": "0.1.15",
"@uform/utils": "0.1.8",
"@uform/validator": "0.1.8",
"classnames": "^2.2.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/core",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand Down
46 changes: 27 additions & 19 deletions packages/core/src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,56 @@ export class Field {
this.destructed = false
this.loading = false
this.errors = []
this.props = {}
this.effectErrors = []
this.initialized = false
this.initialize(options)
this.initialized = true
}

initialize(options) {
const editable = this.getEditableFromProps(options.props)
const rules = this.getRulesFromProps(options.props)
this.value = !isEmpty(options.value) ? clone(options.value) : this.value
this.initialValue = !isEmpty(options.initialValue)
? options.initialValue
: !isEmpty(this.initialValue)
? this.initialValue
: this.getInitialValueFromProps(options.props)
this.name = !isEmpty(options.name) ? options.name : this.name || ''
this.namePath = resolveFieldPath(this.name)
this.editable = !isEmpty(editable)
? editable
: isEmpty(this.editable)
? this.editable
: this.getContextEditable()

this.path = resolveFieldPath(
!isEmpty(options.path) ? options.path : this.path || []
)
this.rules = !isEmpty(rules) ? rules : this.rules
this.required = hasRequired(this.rules)
this.props = !isEmpty(options.props)
? !isEmpty(this.props)

if (isEmpty(options.props)) {
this.initialValue = !isEmpty(options.initialValue)
? options.initialValue
: this.initialValue
} else {
this.initialValue = !isEmpty(options.initialValue)
? options.initialValue
: !isEmpty(this.initialValue)
? this.initialValue
: this.getInitialValueFromProps(options.props)
this.props = !isEmpty(this.props)
? { ...this.props, ...clone(options.props) }
: clone(options.props)
: this.props || {}
if (this.removed) {
this.removed = false
this.visible = true
const editable = this.getEditableFromProps(options.props)
this.editable = !isEmpty(editable) ? editable : this.getContextEditable()
}

if (!this.initialized) {
if (isEmpty(this.value) && !isEmpty(this.initialValue)) {
this.value = clone(this.initialValue)
this.context.setIn(this.name, this.value)
this.context.setInitialValueIn(this.name, this.initialValue)
}
}

if (this.removed) {
this.removed = false
this.visible = true
this.context.triggerEffect('onFieldChange', this.publishState())
}

if (isFn(options.onChange)) {
this.onChange(options.onChange)
}
Expand Down Expand Up @@ -192,14 +199,15 @@ export class Field {
this.notify()
}

restore() {
mount() {
if (this.removed) {
this.visible = true
this.removed = false
this.context.triggerEffect('onFieldChange', this.publishState())
}
}

remove() {
unmount() {
this.value = undefined
this.initialValue = undefined
this.visible = false
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ export class Form {
const field = this.fields[name]
if (field) {
field.initialize({
...options,
path: options.path,
onChange: options.onChange,
value: !isEmpty(value) ? value : initialValue,
initialValue: initialValue
})
this.asyncUpdate(() => {
this.updateFieldStateFromBuffer(field)
})
this.triggerEffect('onFieldChange', field.publishState())
} else {
this.fields[name] = new Field(this, {
name,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const createForm = ({

form.syncUpdate(() => {
form.triggerEffect('onFormInit', form.publishState())
fields.forEach(field => {
form.triggerEffect('onFieldChange', field.publishState())
})
})
return form
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/next",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand All @@ -21,7 +21,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/react": "0.1.14",
"@uform/react": "0.1.15",
"@uform/utils": "0.1.8",
"classnames": "^2.2.6",
"moveto": "^1.7.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/printer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/printer",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand All @@ -20,7 +20,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/react": "0.1.14",
"@uform/react": "0.1.15",
"react-modal": "^3.8.1",
"styled-components": "^4.1.1"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/react",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand All @@ -20,7 +20,7 @@
"react-dom": ">=16.8.0"
},
"dependencies": {
"@uform/core": "0.1.14",
"@uform/core": "0.1.15",
"@uform/utils": "0.1.8",
"@uform/validator": "0.1.8",
"pascal-case": "^2.0.1",
Expand Down
33 changes: 32 additions & 1 deletion packages/react/src/__tests__/effects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ beforeEach(() => {
})
registerFormField(
'string',
connect()(props => <input {...props} value={props.value || ''} />)
connect()(props =>
props.disabled ? (
'Disabled'
) : (
<input {...props} value={props.value || ''} />
)
)
)
})

Expand Down Expand Up @@ -130,3 +136,28 @@ test('onFieldChange will trigger with initialValues', async () => {
expect(callback.mock.calls[0][0].value).toBe(undefined)
expect(callback.mock.calls[1][0].value).toBe(123)
})

test('setFieldState x-props with onFormInit', async () => {
const TestComponent = () => {
return (
<SchemaForm
effects={($, { setFieldState }) => {
$('onFormInit').subscribe(() => {
setFieldState('aaa', state => {
state.props['x-props'].disabled = true
})
})
}}
>
<Field name='aaa' type='string' x-props={{ disabled: false }} />
<button type='submit' data-testid='btn'>
Submit
</button>
</SchemaForm>
)
}

const { queryByText } = render(<TestComponent />)
await sleep(33)
expect(queryByText('Disabled')).toBeVisible()
})
4 changes: 2 additions & 2 deletions packages/react/src/state/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const StateField = createHOC((options, Field) => {

componentWillUnmount() {
this.unmounted = true
this.field.remove()
this.field.unmount()
}

componentDidMount() {
this.unmounted = false
this.field.restore()
this.field.mount()
}

componentDidUpdate(prevProps) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/utils",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/validator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uform/validator",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",
"main": "lib",
"repository": {
Expand All @@ -18,7 +18,7 @@
"@babel/runtime": "^7.4.4"
},
"dependencies": {
"@uform/utils": "0.1.14"
"@uform/utils": "0.1.15"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit bc3125d

Please sign in to comment.