From 2656a9fad8d9253be4cdaa5a9b4932d824804f51 Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 26 Nov 2018 13:51:47 +0700 Subject: [PATCH] redux: completed setters! --- src/modules/Editor.js | 66 +++++++++++++++++++++++-------------- src/redux/user/actions.js | 5 +++ src/redux/user/constants.js | 5 +++ src/redux/user/reducer.js | 11 +++++++ 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 13797eb..76f7987 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -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, }); diff --git a/src/redux/user/actions.js b/src/redux/user/actions.js index 77463ca..542e788 100644 --- a/src/redux/user/actions.js +++ b/src/redux/user/actions.js @@ -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 }); diff --git a/src/redux/user/constants.js b/src/redux/user/constants.js index a3f4549..bc2fc2b 100644 --- a/src/redux/user/constants.js +++ b/src/redux/user/constants.js @@ -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', }; diff --git a/src/redux/user/reducer.js b/src/redux/user/reducer.js index b9cfde1..9ad0c8d 100644 --- a/src/redux/user/reducer.js +++ b/src/redux/user/reducer.js @@ -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 = {