redux: completed setters!

This commit is contained in:
muerwre 2018-11-26 13:51:47 +07:00
parent 0d47cd8773
commit 2656a9fad8
4 changed files with 62 additions and 25 deletions

View file

@ -9,23 +9,31 @@ import { DEFAULT_LOGO } from '$constants/logos';
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
import { getUrlData, pushPath } from '$utils/history';
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 {
constructor({
// container,
// mode,
// setMode,
setRouterPoints,
// setRouterPoints,
// setTotalDist,
setActiveSticker,
setLogo,
// setEditing,
setTitle,
setAddress,
// triggerOnChange,
clearChanged,
// getTitle,
// clearChanged,
// setActiveSticker,
// setLogo,
// setTitle,
// setAddress,
}) {
this.logo = DEFAULT_LOGO;
this.owner = null;
@ -33,7 +41,8 @@ export class Editor {
this.initialData = {};
const {
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints, map: { map }
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints,
map: { map }
} = this;
this.poly = new Poly({
@ -41,7 +50,7 @@ export class Editor {
});
this.stickers = new Stickers({ map, lockMapClicks, triggerOnChange });
this.router = new Router({
map, lockMapClicks, setRouterPoints, changeMode, pushPolyPoints
map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints
});
this.shotter = new Shotter({ map });
@ -73,15 +82,15 @@ export class Editor {
};
this.activeSticker = null;
this.clearChanged = clearChanged;
this.setActiveSticker = setActiveSticker;
this.setLogo = setLogo;
this.mode = MODES.NONE;
// this.clearChanged = clearChanged;
// this.setActiveSticker = setActiveSticker;
// this.setLogo = setLogo;
// this.setMode = setMode;
// this.setEditing = setEditing;
this.setTitle = setTitle;
this.setAddress = setAddress;
// this.setTitle = setTitle;
// this.setAddress = setAddress;
// this.getUser = getUser;
this.mode = MODES.NONE;
// this.getTitle = getTitle;
map.addEventListener('mouseup', this.onClick);
@ -93,10 +102,16 @@ export class Editor {
getTitle = () => store.getState().title;
getEditing = () => store.getState().editing;
setEditing = editing => store.dispatch(setEditing(editing));
setMode = mode => store.dispatch(setMode(mode));
setDistance = distance => store.dispatch(setDistance(distance));
setChanged = changed => store.dispatch(setChanged(changed));
setEditing = value => store.dispatch(setEditing(value));
setDistance = value => store.dispatch(setDistance(value));
setChanged = value => store.dispatch(setChanged(value));
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 = () => {
if (!this.getEditing()) return;
@ -312,15 +327,16 @@ export class Editor {
export const editor = new Editor({
// setMode: this.setMode,
// setRouterPoints: this.setRouterPoints,
// setTotalDist: this.setTotalDist,
// setActiveSticker: this.setActiveSticker,
// setLogo: this.setLogo,
// setEditing: this.setEditing,
// setTitle: this.setTitle,
// setAddress: this.setAddress,
// getUser: this.getUser,
// triggerOnChange: this.triggerOnChange,
// clearChanged: this.clearChanged,
// getTitle: this.getTitle,
// setRouterPoints: this.setRouterPoints,
// setActiveSticker: this.setActiveSticker,
// setLogo: this.setLogo,
// setTitle: this.setTitle,
// setAddress: this.setAddress,
// clearChanged: this.clearChanged,
});

View file

@ -5,3 +5,8 @@ export const setEditing = editing => ({ type: ACTIONS.SET_EDITING, editing });
export const setMode = mode => ({ type: ACTIONS.SET_MODE, mode });
export const setDistance = distance => ({ type: ACTIONS.SET_DISTANCE, distance });
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 });

View file

@ -5,4 +5,9 @@ export const ACTIONS = {
SET_MODE: 'SET_MODE',
SET_DISTANCE: 'SET_DISTANCE',
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',
};

View file

@ -15,12 +15,23 @@ const setUser = (state, { user }) => ({
const setEditing = (state, { editing }) => ({ ...state, editing });
const setMode = (state, { mode }) => ({ ...state, mode });
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 = {
[ACTIONS.SET_USER]: setUser,
[ACTIONS.SET_EDITING]: setEditing,
[ACTIONS.SET_MODE]: setMode,
[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 = {