Refactoring to take advantage of Immer's drafts
This commit is contained in:
parent
d5196f4340
commit
3a7d4987a3
|
@ -60,12 +60,29 @@ const nbTilesY = _.ceil(mapState.viewport.height / tileSize) + 4;
|
|||
|
||||
*/
|
||||
|
||||
const computeStateFromScope = (scope: MapScope) => {
|
||||
const newScope = _.cloneDeep(scope);
|
||||
let state: MapState = {} as MapState;
|
||||
state.scope = newScope;
|
||||
state.tiles = {} as TilesDescription;
|
||||
state.slippy = {} as SlippyState;
|
||||
let initialMapState: MapState = {
|
||||
scope: initialMapScope,
|
||||
slippy: {
|
||||
scale: 1,
|
||||
translation: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
tiles: {
|
||||
first: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
nb: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
zoom: 0,
|
||||
},
|
||||
};
|
||||
|
||||
const evaluateStateFromScope = (state: MapState) => {
|
||||
state.tiles.zoom = _.round(state.scope.zoom);
|
||||
const softZoom = state.scope.zoom - state.tiles.zoom;
|
||||
state.slippy.scale = 2 ** softZoom;
|
||||
|
@ -94,18 +111,20 @@ const computeStateFromScope = (scope: MapScope) => {
|
|||
x: tilesCenterTargetLocation.x - tilesCenterActualLocation.x,
|
||||
y: tilesCenterTargetLocation.y - tilesCenterActualLocation.y,
|
||||
};
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
const initialMapState: MapState = computeStateFromScope(initialMapScope);
|
||||
evaluateStateFromScope(initialMapState);
|
||||
|
||||
const reevaluateState = (state: MapState) => {};
|
||||
|
||||
|
||||
|
||||
const mapSlice = createSlice({
|
||||
name: 'map',
|
||||
initialState: initialMapState,
|
||||
reducers: {
|
||||
resize: (state) => {
|
||||
return computeStateFromScope(state.scope);
|
||||
evaluateStateFromScope(state);
|
||||
},
|
||||
shift: (state, action) => {
|
||||
state.slippy.translation = {
|
||||
|
|
Loading…
Reference in New Issue