Browse Source

初始化store

master
Cmen 3 years ago
parent
commit
988b9300cb
  1. 4
      package.json
  2. 6
      src/app/index.tsx
  3. 5
      src/index.tsx
  4. 33
      src/store/index.ts
  5. 8
      src/store/initState.ts
  6. 11
      src/store/reducers.ts
  7. 14
      src/store/type.ts
  8. 14
      yarn.lock

4
package.json

@ -8,10 +8,12 @@
}, },
"dependencies": { "dependencies": {
"antd": "^4.16.13", "antd": "^4.16.13",
"immer": "^9.0.7",
"less": "^4.1.2", "less": "^4.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2",
"redux": "^4.1.2"
}, },
"devDependencies": { "devDependencies": {
"@amap/amap-jsapi-types": "^0.0.8", "@amap/amap-jsapi-types": "^0.0.8",

6
src/app/index.tsx

@ -0,0 +1,6 @@
const App = () => {
return <h1></h1>
}
export default App;

5
src/index.tsx

@ -1,11 +1,14 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { store, StoreContext } from './store';
import { Editor } from './editor'; import { Editor } from './editor';
import './index.less'; import './index.less';
ReactDOM.render( ReactDOM.render(
<Editor />, <StoreContext.Provider value={store}>
<Editor />
</StoreContext.Provider>,
document.getElementById('app') document.getElementById('app')
) )

33
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<IEditorState, Action>;
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<IStore | null>(null) as Context<IStore>;
export const useStore = () => {
const store = useContext(StoreContext);
return store;
};

8
src/store/initState.ts

@ -0,0 +1,8 @@
import { IEditorState } from "./type";
export const initState: IEditorState = {
map: {
polygons: []
}
}

11
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;
}

14
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,
}

14
yarn.lock

@ -365,7 +365,7 @@
"@babel/plugin-syntax-jsx" "^7.16.7" "@babel/plugin-syntax-jsx" "^7.16.7"
"@babel/types" "^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" version "7.16.7"
resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.7.tgz#03ff99f64106588c9c403c6ecb8c3bafbbdff1fa" resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.7.tgz#03ff99f64106588c9c403c6ecb8c3bafbbdff1fa"
integrity sha512-9E9FJowqAsytyOY6LG+1KuueckRL+aQW+mKvXRXnuFGyRAyepJPmEo9vgMfXUA6O9u3IeEdv9MAkppFcaQwogQ== 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" resolved "https://registry.nlark.com/image-size/download/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c"
integrity sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w= 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: is-core-module@^2.8.0:
version "2.8.1" version "2.8.1"
resolved "https://registry.npmmirror.com/is-core-module/download/is-core-module-2.8.1.tgz#f59fdfca701d5879d0a6b100a40aa1560ce27211" 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" loose-envify "^1.1.0"
object-assign "^4.1.1" 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: regenerator-runtime@^0.13.4:
version "0.13.9" version "0.13.9"
resolved "https://registry.npmmirror.com/regenerator-runtime/download/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52" resolved "https://registry.npmmirror.com/regenerator-runtime/download/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"

Loading…
Cancel
Save