mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
redux: completed setters!
This commit is contained in:
parent
0d47cd8773
commit
2656a9fad8
4 changed files with 62 additions and 25 deletions
|
@ -9,23 +9,31 @@ import { DEFAULT_LOGO } from '$constants/logos';
|
||||||
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
|
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
|
||||||
import { getUrlData, pushPath } from '$utils/history';
|
import { getUrlData, pushPath } from '$utils/history';
|
||||||
import { store } from '$redux/store';
|
import { store } from '$redux/store';
|
||||||
import { setChanged, setDistance, setEditing, setMode } from '$redux/user/actions';
|
import {
|
||||||
|
setActiveSticker, setAddress,
|
||||||
|
setChanged,
|
||||||
|
setDistance,
|
||||||
|
setEditing,
|
||||||
|
setLogo,
|
||||||
|
setRouterPoints,
|
||||||
|
setTitle
|
||||||
|
} from '$redux/user/actions';
|
||||||
|
|
||||||
export class Editor {
|
export class Editor {
|
||||||
constructor({
|
constructor({
|
||||||
// container,
|
// container,
|
||||||
// mode,
|
// mode,
|
||||||
// setMode,
|
// setMode,
|
||||||
setRouterPoints,
|
// setRouterPoints,
|
||||||
// setTotalDist,
|
// setTotalDist,
|
||||||
setActiveSticker,
|
|
||||||
setLogo,
|
|
||||||
// setEditing,
|
// setEditing,
|
||||||
setTitle,
|
|
||||||
setAddress,
|
|
||||||
// triggerOnChange,
|
// triggerOnChange,
|
||||||
clearChanged,
|
|
||||||
// getTitle,
|
// getTitle,
|
||||||
|
// clearChanged,
|
||||||
|
// setActiveSticker,
|
||||||
|
// setLogo,
|
||||||
|
// setTitle,
|
||||||
|
// setAddress,
|
||||||
}) {
|
}) {
|
||||||
this.logo = DEFAULT_LOGO;
|
this.logo = DEFAULT_LOGO;
|
||||||
this.owner = null;
|
this.owner = null;
|
||||||
|
@ -33,7 +41,8 @@ export class Editor {
|
||||||
this.initialData = {};
|
this.initialData = {};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints, map: { map }
|
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints,
|
||||||
|
map: { map }
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
this.poly = new Poly({
|
this.poly = new Poly({
|
||||||
|
@ -41,7 +50,7 @@ export class Editor {
|
||||||
});
|
});
|
||||||
this.stickers = new Stickers({ map, lockMapClicks, triggerOnChange });
|
this.stickers = new Stickers({ map, lockMapClicks, triggerOnChange });
|
||||||
this.router = new Router({
|
this.router = new Router({
|
||||||
map, lockMapClicks, setRouterPoints, changeMode, pushPolyPoints
|
map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints
|
||||||
});
|
});
|
||||||
this.shotter = new Shotter({ map });
|
this.shotter = new Shotter({ map });
|
||||||
|
|
||||||
|
@ -73,15 +82,15 @@ export class Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.activeSticker = null;
|
this.activeSticker = null;
|
||||||
this.clearChanged = clearChanged;
|
this.mode = MODES.NONE;
|
||||||
this.setActiveSticker = setActiveSticker;
|
// this.clearChanged = clearChanged;
|
||||||
this.setLogo = setLogo;
|
// this.setActiveSticker = setActiveSticker;
|
||||||
|
// this.setLogo = setLogo;
|
||||||
// this.setMode = setMode;
|
// this.setMode = setMode;
|
||||||
// this.setEditing = setEditing;
|
// this.setEditing = setEditing;
|
||||||
this.setTitle = setTitle;
|
// this.setTitle = setTitle;
|
||||||
this.setAddress = setAddress;
|
// this.setAddress = setAddress;
|
||||||
// this.getUser = getUser;
|
// this.getUser = getUser;
|
||||||
this.mode = MODES.NONE;
|
|
||||||
// this.getTitle = getTitle;
|
// this.getTitle = getTitle;
|
||||||
|
|
||||||
map.addEventListener('mouseup', this.onClick);
|
map.addEventListener('mouseup', this.onClick);
|
||||||
|
@ -93,10 +102,16 @@ export class Editor {
|
||||||
getTitle = () => store.getState().title;
|
getTitle = () => store.getState().title;
|
||||||
getEditing = () => store.getState().editing;
|
getEditing = () => store.getState().editing;
|
||||||
|
|
||||||
setEditing = editing => store.dispatch(setEditing(editing));
|
setEditing = value => store.dispatch(setEditing(value));
|
||||||
setMode = mode => store.dispatch(setMode(mode));
|
setDistance = value => store.dispatch(setDistance(value));
|
||||||
setDistance = distance => store.dispatch(setDistance(distance));
|
setChanged = value => store.dispatch(setChanged(value));
|
||||||
setChanged = changed => store.dispatch(setChanged(changed));
|
setRouterPoints = value => store.dispatch(setRouterPoints(value));
|
||||||
|
setActiveSticker = value => store.dispatch(setActiveSticker(value));
|
||||||
|
setLogo = value => store.dispatch(setLogo(value));
|
||||||
|
setTitle = value => store.dispatch(setTitle(value));
|
||||||
|
setAddress = value => store.dispatch(setAddress(value));
|
||||||
|
|
||||||
|
clearChanged = () => store.direction(setChanged(false));
|
||||||
|
|
||||||
triggerOnChange = () => {
|
triggerOnChange = () => {
|
||||||
if (!this.getEditing()) return;
|
if (!this.getEditing()) return;
|
||||||
|
@ -312,15 +327,16 @@ export class Editor {
|
||||||
|
|
||||||
export const editor = new Editor({
|
export const editor = new Editor({
|
||||||
// setMode: this.setMode,
|
// setMode: this.setMode,
|
||||||
// setRouterPoints: this.setRouterPoints,
|
|
||||||
// setTotalDist: this.setTotalDist,
|
// setTotalDist: this.setTotalDist,
|
||||||
// setActiveSticker: this.setActiveSticker,
|
|
||||||
// setLogo: this.setLogo,
|
|
||||||
// setEditing: this.setEditing,
|
// setEditing: this.setEditing,
|
||||||
// setTitle: this.setTitle,
|
|
||||||
// setAddress: this.setAddress,
|
|
||||||
// getUser: this.getUser,
|
// getUser: this.getUser,
|
||||||
// triggerOnChange: this.triggerOnChange,
|
// triggerOnChange: this.triggerOnChange,
|
||||||
// clearChanged: this.clearChanged,
|
|
||||||
// getTitle: this.getTitle,
|
// getTitle: this.getTitle,
|
||||||
|
|
||||||
|
// setRouterPoints: this.setRouterPoints,
|
||||||
|
// setActiveSticker: this.setActiveSticker,
|
||||||
|
// setLogo: this.setLogo,
|
||||||
|
// setTitle: this.setTitle,
|
||||||
|
// setAddress: this.setAddress,
|
||||||
|
// clearChanged: this.clearChanged,
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,3 +5,8 @@ export const setEditing = editing => ({ type: ACTIONS.SET_EDITING, editing });
|
||||||
export const setMode = mode => ({ type: ACTIONS.SET_MODE, mode });
|
export const setMode = mode => ({ type: ACTIONS.SET_MODE, mode });
|
||||||
export const setDistance = distance => ({ type: ACTIONS.SET_DISTANCE, distance });
|
export const setDistance = distance => ({ type: ACTIONS.SET_DISTANCE, distance });
|
||||||
export const setChanged = changed => ({ type: ACTIONS.SET_CHANGED, changed });
|
export const setChanged = changed => ({ type: ACTIONS.SET_CHANGED, changed });
|
||||||
|
export const setRouterPoints = routerPoints => ({ type: ACTIONS.SET_ROUTER_POINTS, routerPoints });
|
||||||
|
export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STICKER, activeSticker });
|
||||||
|
export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo });
|
||||||
|
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
|
||||||
|
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
|
||||||
|
|
|
@ -5,4 +5,9 @@ export const ACTIONS = {
|
||||||
SET_MODE: 'SET_MODE',
|
SET_MODE: 'SET_MODE',
|
||||||
SET_DISTANCE: 'SET_DISTANCE',
|
SET_DISTANCE: 'SET_DISTANCE',
|
||||||
SET_CHANGED: 'SET_CHANGED',
|
SET_CHANGED: 'SET_CHANGED',
|
||||||
|
SET_ROUTER_POINTS: 'SET_ROUTER_POINTS',
|
||||||
|
SET_ACTIVE_STICKER: 'SET_ACTIVE_STICKER',
|
||||||
|
SET_LOGO: 'SET_LOGO',
|
||||||
|
SET_TITLE: 'SET_TITLE',
|
||||||
|
SET_ADDRESS: 'SET_ADDRESS',
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,12 +15,23 @@ const setUser = (state, { user }) => ({
|
||||||
const setEditing = (state, { editing }) => ({ ...state, editing });
|
const setEditing = (state, { editing }) => ({ ...state, editing });
|
||||||
const setMode = (state, { mode }) => ({ ...state, mode });
|
const setMode = (state, { mode }) => ({ ...state, mode });
|
||||||
const setDistance = (state, { distance }) => ({ ...state, distance });
|
const setDistance = (state, { distance }) => ({ ...state, distance });
|
||||||
|
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
|
||||||
|
|
||||||
|
const setActiveSticker = (state, { activeSticker }) => ({ ...state, activeSticker });
|
||||||
|
const setLogo = (state, { logo }) => ({ ...state, logo });
|
||||||
|
const setTitle = (state, { title }) => ({ ...state, title });
|
||||||
|
const setAddress = (state, { address }) => ({ ...state, address });
|
||||||
|
|
||||||
const HANDLERS = {
|
const HANDLERS = {
|
||||||
[ACTIONS.SET_USER]: setUser,
|
[ACTIONS.SET_USER]: setUser,
|
||||||
[ACTIONS.SET_EDITING]: setEditing,
|
[ACTIONS.SET_EDITING]: setEditing,
|
||||||
[ACTIONS.SET_MODE]: setMode,
|
[ACTIONS.SET_MODE]: setMode,
|
||||||
[ACTIONS.SET_DISTANCE]: setDistance,
|
[ACTIONS.SET_DISTANCE]: setDistance,
|
||||||
|
[ACTIONS.SET_ROUTER_POINTS]: setRouterPoints,
|
||||||
|
[ACTIONS.SET_ACTIVE_STICKER]: setActiveSticker,
|
||||||
|
[ACTIONS.SET_LOGO]: setLogo,
|
||||||
|
[ACTIONS.SET_TITLE]: setTitle,
|
||||||
|
[ACTIONS.SET_ADDRESS]: setAddress,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const INITIAL_STATE = {
|
export const INITIAL_STATE = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue