diff --git a/package.json b/package.json index 31a89a0..6799e56 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,12 @@ }, "dependencies": { "antd": "^4.16.13", + "immer": "^9.0.7", "less": "^4.1.2", "lodash": "^4.17.21", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "redux": "^4.1.2" }, "devDependencies": { "@amap/amap-jsapi-types": "^0.0.8", diff --git a/src/app/index.tsx b/src/app/index.tsx new file mode 100644 index 0000000..4c8521b --- /dev/null +++ b/src/app/index.tsx @@ -0,0 +1,6 @@ + +const App = () => { + return

首页

+} + +export default App; \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index eabfc5a..dc87461 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,11 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import { store, StoreContext } from './store'; import { Editor } from './editor'; import './index.less'; ReactDOM.render( - , + + + , document.getElementById('app') ) \ No newline at end of file diff --git a/src/store/index.ts b/src/store/index.ts new file mode 100644 index 0000000..6070603 --- /dev/null +++ b/src/store/index.ts @@ -0,0 +1,33 @@ +import { createStore, Store } from "redux"; +import { createContext, Context, useContext } from "react"; +import { reducer, Action } from "./reducers"; +import { IEditorState } from "./type"; + +type IStore = Store; +const store: IStore = createStore(reducer); + +export { store }; + +// export class Store { +// // editorState: IEditorState; +// // mapState: IMapState; + +// constructor() { +// this.editorState = {}; +// this.mapState = { +// polygons: [], +// }; +// } + +// addPolygon() { +// // +// } +// } + + +export const StoreContext = createContext(null) as Context; + +export const useStore = () => { + const store = useContext(StoreContext); + return store; +}; diff --git a/src/store/initState.ts b/src/store/initState.ts new file mode 100644 index 0000000..5e4737d --- /dev/null +++ b/src/store/initState.ts @@ -0,0 +1,8 @@ +import { IEditorState } from "./type"; + + +export const initState: IEditorState = { + map: { + polygons: [] + } +} \ No newline at end of file diff --git a/src/store/reducers.ts b/src/store/reducers.ts new file mode 100644 index 0000000..351fd99 --- /dev/null +++ b/src/store/reducers.ts @@ -0,0 +1,11 @@ +import { createStore } from "redux"; +import { initState } from "./initState"; + +export type Action = { + type: string; + payload: any; +} + +export function reducer(state = initState, action: Action) { + return state; +} diff --git a/src/store/type.ts b/src/store/type.ts new file mode 100644 index 0000000..c2718af --- /dev/null +++ b/src/store/type.ts @@ -0,0 +1,14 @@ + + +export interface IPolygon { + id: string; + name: string; +} + +export interface IMapState { + polygons: IPolygon[]; +} + +export interface IEditorState { + map: IMapState, +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f089d17..e048141 100644 --- a/yarn.lock +++ b/yarn.lock @@ -365,7 +365,7 @@ "@babel/plugin-syntax-jsx" "^7.16.7" "@babel/types" "^7.16.7" -"@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.4", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.8.4": +"@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.4", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2": version "7.16.7" resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.7.tgz#03ff99f64106588c9c403c6ecb8c3bafbbdff1fa" integrity sha512-9E9FJowqAsytyOY6LG+1KuueckRL+aQW+mKvXRXnuFGyRAyepJPmEo9vgMfXUA6O9u3IeEdv9MAkppFcaQwogQ== @@ -953,6 +953,11 @@ image-size@~0.5.0: resolved "https://registry.nlark.com/image-size/download/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c" integrity sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w= +immer@^9.0.7: + version "9.0.7" + resolved "https://registry.npmmirror.com/immer/download/immer-9.0.7.tgz#b6156bd7db55db7abc73fd2fdadf4e579a701075" + integrity sha512-KGllzpbamZDvOIxnmJ0jI840g7Oikx58lBPWV0hUh7dtAyZpFqqrBZdKka5GlTwMTZ1Tjc/bKKW4VSFAt6BqMA== + is-core-module@^2.8.0: version "2.8.1" resolved "https://registry.npmmirror.com/is-core-module/download/is-core-module-2.8.1.tgz#f59fdfca701d5879d0a6b100a40aa1560ce27211" @@ -1528,6 +1533,13 @@ react@^17.0.2: loose-envify "^1.1.0" object-assign "^4.1.1" +redux@^4.1.2: + version "4.1.2" + resolved "https://registry.npmmirror.com/redux/download/redux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104" + integrity sha512-SH8PglcebESbd/shgf6mii6EIoRM0zrQyjcuQ+ojmfxjTtE0z9Y8pa62iA/OJ58qjP6j27uyW4kUF4jl/jd6sw== + dependencies: + "@babel/runtime" "^7.9.2" + regenerator-runtime@^0.13.4: version "0.13.9" resolved "https://registry.npmmirror.com/regenerator-runtime/download/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"