Skip to content

Commit

Permalink
feat(project): remove mobx-react-lite
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Mar 10, 2021
1 parent 7d24537 commit 7078616
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 51 deletions.
3 changes: 2 additions & 1 deletion packages/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@types/react": ">=16.8.0 || >=17.0.0",
"@types/react-dom": ">=16.8.0 || >=17.0.0",
"antd": "^4.0.0",
"mobx": "^6.0.3",
"react": ">=16.8.0 || >=17.0.0",
"react-dom": ">=16.8.0"
},
Expand All @@ -41,6 +40,8 @@
"@formily/core": "^2.0.0-beta.3",
"@formily/react": "^2.0.0-beta.3",
"@formily/shared": "^2.0.0-beta.3",
"@formily/reactive": "^2.0.0-beta.3",
"@formily/reactive-react": "^2.0.0-beta.3",
"classnames": "^2.2.6",
"react-sortable-hoc": "^1.11.0",
"react-sticky-box": "^0.9.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/form-collapse/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useMemo } from 'react'
import { Collapse, Badge } from 'antd'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import { CollapseProps, CollapsePanelProps } from 'antd/lib/collapse'
import {
useField,
Expand Down Expand Up @@ -56,7 +56,7 @@ const usePanels = () => {
}

const createFormCollapse = (defaultActiveKeys?: ActiveKeys) => {
const formCollapse = makeAutoObservable({
const formCollapse = createModel({
activeKeys: defaultActiveKeys || [],
setActiveKeys(keys: ActiveKeys) {
formCollapse.activeKeys = keys
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/form-step/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from 'react'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import { Steps } from 'antd'
import cls from 'classnames'
import { StepsProps, StepProps } from 'antd/lib/steps'
Expand Down Expand Up @@ -93,7 +93,7 @@ const createFormStep = (defaultCurrent = 0): IFormStep => {
}
}

const formStep: IFormStep = makeAutoObservable({
const formStep: IFormStep = createModel({
connect(steps, field) {
env.steps = steps
env.form = field?.form
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/form-tab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useMemo } from 'react'
import { Tabs, Badge } from 'antd'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import { TabPaneProps, TabsProps } from 'antd/lib/tabs'
import {
useField,
Expand Down Expand Up @@ -51,7 +51,7 @@ const useTabs = () => {
}

const createFormTab = (defaultActiveKey?: string) => {
const formTab = makeAutoObservable({
const formTab = createModel({
activeKey: defaultActiveKey,
setActiveKey(key: string) {
formTab.activeKey = key
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/src/upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
UploadProps as AntdUploadProps,
DraggerProps as AntdDraggerProps,
} from 'antd/lib/upload'
import { reaction } from 'mobx'
import { reaction } from '@formily/reactive'
import { UploadFile } from 'antd/lib/upload/interface'
import { isArr, toArr } from '@formily/shared'
import { UPLOAD_PLACEHOLDER } from './placeholder'
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"build:docs": "dumi build"
},
"peerDependencies": {
"@types/react": ">=16.8.0 || >=17.0.0",
"mobx": "^6.0.3"
"@types/react": ">=16.8.0 || >=17.0.0"
},
"devDependencies": {
"dumi": "^1.1.0-rc.8"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
parseValidatorDescriptions,
} from '@formily/validator'
import {
define,
defineModel,
observable,
reaction,
batch,
Expand Down Expand Up @@ -145,7 +145,7 @@ export class Field<
}

protected makeObservable() {
define(this, {
defineModel(this, {
title: observable.ref,
description: observable.ref,
dataSource: observable.ref,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/Form.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
define,
defineModel,
observable,
batch,
toJS,
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Form<ValueType extends object = any> {
}

protected makeObservable() {
define(this, {
defineModel(this, {
fields: observable.shallow,
initialized: observable.ref,
validating: observable.ref,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/Graph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { define, batch } from '@formily/reactive'
import { defineModel, batch } from '@formily/reactive'
import { each, FormPath } from '@formily/shared'
import { IFormGraph } from '../types'
import { Form } from './Form'
Expand All @@ -14,7 +14,7 @@ export class Graph {

constructor(form: Form) {
this.form = form
define(this, {
defineModel(this, {
setGraph: batch,
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/VoidField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
isValid,
toArr,
} from '@formily/shared'
import { define, observable, autorun, batch } from '@formily/reactive'
import { defineModel, observable, autorun, batch } from '@formily/reactive'
import {
JSXComponent,
JSXComponenntProps,
Expand Down Expand Up @@ -93,7 +93,7 @@ export class VoidField<Decorator = any, Component = any, TextType = any> {
}

protected makeObservable() {
define(this, {
defineModel(this, {
title: observable.ref,
description: observable.ref,
selfDisplay: observable.ref,
Expand Down
6 changes: 2 additions & 4 deletions packages/json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
"build:esm": "tsc --declaration --module es2015 --outDir esm",
"build:umd": "rollup --config"
},
"peerDependencies": {
"mobx": "^6.0.3"
},
"dependencies": {
"@formily/core": "^2.0.0-beta.3",
"@formily/shared": "^2.0.0-beta.3"
"@formily/shared": "^2.0.0-beta.3",
"@formily/reactive": "^2.0.0-beta.3"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions packages/json-schema/src/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { compile, registerCompiler, shallowCompile } from '../compiler'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import { Schema } from '../schema'

test('compile', () => {
Expand Down Expand Up @@ -40,7 +40,7 @@ test('compile', () => {
const compiledActions = compile(actions)
expect(compiledActions).toEqual(actions)
expect(compiledActions['expression']).toEqual('{{123}}')
const observable = makeAutoObservable({
const observable = createModel({
aa: 123,
bb: 321,
expression: '{{123}}',
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schema/src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArr, isFn, isPlainObj, isStr, reduce } from '@formily/shared'
import { isObservable } from 'mobx'
import { isObservable } from '@formily/reactive'
import { Schema } from './schema'

const ExpRE = /^\s*\{\{(.*)\}\}\s*$/
Expand Down
4 changes: 2 additions & 2 deletions packages/json-schema/src/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runInAction } from 'mobx'
import { batch } from '@formily/reactive'
import {
isBool,
isArr,
Expand Down Expand Up @@ -208,7 +208,7 @@ const getSchemaFieldReactions = (
compile: (expression: any) => any
) => {
if (!request) return
runInAction(() => {
batch(() => {
if (request.state) {
field.setState((state) => patchState(state, compile(request.state)))
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@alifd/next": "^1.19.0",
"@types/react": ">=16.8.0 || >=17.0.0",
"@types/react-dom": ">=16.8.0 || >=17.0.0",
"mobx": "^6.0.3",
"react": ">=16.8.0 || >=17.0.0",
"react-dom": ">=16.8.0"
},
Expand All @@ -41,6 +40,8 @@
"@formily/json-schema": "^2.0.0-beta.3",
"@formily/react": "^2.0.0-beta.3",
"@formily/shared": "^2.0.0-beta.3",
"@formily/reactive": "^2.0.0-beta.3",
"@formily/reactive-react": "^2.0.0-beta.3",
"classnames": "^2.2.6",
"react-sortable-hoc": "^1.11.0",
"react-sticky-box": "^0.9.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/form-collapse/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useMemo } from 'react'
import { Collapse, Badge } from '@alifd/next'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import {
CollapseProps,
PanelProps as CollapsePanelProps,
Expand Down Expand Up @@ -63,7 +63,7 @@ const usePanels = () => {
}

const createFormCollapse = (defaultActiveKeys?: ActiveKeys) => {
const formCollapse = makeAutoObservable({
const formCollapse = createModel({
activeKeys: defaultActiveKeys || [],
setActiveKeys(keys: ActiveKeys) {
formCollapse.activeKeys = keys
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/form-step/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from 'react'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import cls from 'classnames'
import {
StepProps as StepsProps,
Expand Down Expand Up @@ -96,7 +96,7 @@ const createFormStep = (defaultCurrent = 0): IFormStep => {
}
}

const formStep: IFormStep = makeAutoObservable({
const formStep: IFormStep = createModel({
connect(steps, field) {
env.steps = steps
env.form = field?.form
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/form-tab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useMemo } from 'react'
import { Tab as Tabs, Badge } from '@alifd/next'
import { makeAutoObservable } from 'mobx'
import { createModel } from '@formily/reactive'
import {
ItemProps as TabPaneProps,
TabProps as TabsProps,
Expand Down Expand Up @@ -54,7 +54,7 @@ const useTabs = () => {
}

const createFormTab = (defaultActiveKey?: string) => {
const formTab = makeAutoObservable({
const formTab = createModel({
activeKey: defaultActiveKey,
setActiveKey(key: string) {
formTab.activeKey = key
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/upload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { useField } from '@formily/react'
import { reaction } from 'mobx'
import { reaction } from '@formily/reactive'
import { Upload as NextUpload } from '@alifd/next'
import { UploadProps, CardProps } from '@alifd/next/lib/upload'
import { isArr, toArr } from '@formily/shared'
Expand Down
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"peerDependencies": {
"@types/react": ">=16.8.0 || >=17.0.0",
"@types/react-dom": ">=16.8.0 || >=17.0.0",
"mobx": "^6.0.3",
"react": ">=16.8.0 || >=17.0.0",
"react-dom": ">=16.8.0 || >=17.0.0"
},
Expand All @@ -43,7 +42,8 @@
"@formily/json-schema": "^2.0.0-beta.3",
"@formily/shared": "^2.0.0-beta.3",
"@formily/validator": "^2.0.0-beta.3",
"mobx-react-lite": "^3.1.6",
"@formily/reactive": "^2.0.0-beta.3",
"@formily/reactive-react": "^2.0.0-beta.3",
"hoist-non-react-statics": "^3.3.2"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/FormConsumer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment } from 'react'
import { isFn } from '@formily/shared'
import { observer } from 'mobx-react-lite'
import { observer } from '@formily/reactive-react'
import { useForm } from '../hooks'
import { IFormSpyProps } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/ReactiveField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from 'react'
import { observer } from 'mobx-react-lite'
import { observer } from '@formily/reactive-react'
import { isFn } from '@formily/shared'
import { isVoidField } from '@formily/core'
interface IReactiveFieldProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/shared/connect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { isFn, isStr, FormPath, each } from '@formily/shared'
import { isVoidField } from '@formily/core'
import { observer } from 'mobx-react-lite'
import { observer } from '@formily/reactive-react'
import { JSXComponent, IComponentMapper, IStateMapper } from '../types'
import { useField } from '../hooks'
import hoistNonReactStatics from 'hoist-non-react-statics'
Expand Down
1 change: 0 additions & 1 deletion packages/reactive-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"peerDependencies": {
"@types/react": ">=16.8.0 || >=17.0.0",
"@types/react-dom": ">=16.8.0 || >=17.0.0",
"mobx": "^6.0.3",
"react": ">=16.8.0 || >=17.0.0",
"react-dom": ">=16.8.0 || >=17.0.0"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/reactive/src/__tests__/define.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { define, observable, autorun } from '..'
import { defineModel, observable, autorun } from '..'
import { observe } from '../observe'
import { FormPath } from '@formily/shared'
import { batch } from '../batch'
Expand All @@ -8,7 +8,7 @@ describe('makeObservable', () => {
const target: any = {
aa: {},
}
define(target, {
defineModel(target, {
aa: observable,
})
const handler = jest.fn()
Expand All @@ -29,7 +29,7 @@ describe('makeObservable', () => {
const target: any = {
aa: {},
}
define(target, {
defineModel(target, {
aa: observable.shallow,
})
const handler = jest.fn()
Expand All @@ -50,7 +50,7 @@ describe('makeObservable', () => {
})
test('box annotation', () => {
const target: any = {}
define(target, {
defineModel(target, {
aa: observable.box,
})
const handler = jest.fn()
Expand All @@ -68,7 +68,7 @@ describe('makeObservable', () => {
})
test('ref annotation', () => {
const target: any = {}
define(target, {
defineModel(target, {
aa: observable.ref,
})
const handler = jest.fn()
Expand All @@ -92,7 +92,7 @@ describe('makeObservable', () => {
target.aa.cc = 312
},
}
define(target, {
defineModel(target, {
aa: observable,
setData: batch,
})
Expand All @@ -113,7 +113,7 @@ describe('makeObservable', () => {
return this.aa + this.bb
},
}
define(target, {
defineModel(target, {
aa: observable,
bb: observable,
cc: observable.computed,
Expand Down
2 changes: 1 addition & 1 deletion packages/reactive/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './batch'
export * from './observable'
export * from './define'
export * from './model'
export * from './autorun'
export * from './tracker'
export * from './observe'
Expand Down
Loading

0 comments on commit 7078616

Please sign in to comment.