Skip to content

Commit

Permalink
UN-12 Technical: Translate redusers (main files) to typescript (#1722)
Browse files Browse the repository at this point in the history
* Reanamed js files

Signed-off-by: Maksim Suslov <maksim.suslov@actionengine.com>

* Moved types from d.ts files

Signed-off-by: Maksim Suslov <maksim.suslov@actionengine.com>
  • Loading branch information
HeimEndyd committed Mar 2, 2022
1 parent fb170ae commit e36cac5
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 170 deletions.
2 changes: 1 addition & 1 deletion src/components/map/locale-panel.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {MapControls} from '../../reducers';
import {MapControls} from 'reducers';

export type LocalePanelProps = {
availableLocales: ReadonlyArray<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/map-control.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Editor, MapControls} from '../../reducers';
import {Editor, MapControls} from 'reducers';
import {Datasets} from 'reducers/vis-state-updaters';
import {FeatureFlags} from '../context';
import {Layer} from 'layers';
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/map-draw-panel.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Editor, MapControls} from '../../reducers';
import {Editor, MapControls} from 'reducers';
import {MapDrawPanelIcons} from './map-control';

export type MapDrawPanelProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/map-legend-panel.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Element} from 'react';
import {Layer} from 'layers';
import {MapControls} from '../../reducers';
import {MapControls} from 'reducers';

interface MapLegendPanelIcons {
legend: ComponentType<any>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/split-map-button.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {MapControls} from '../../reducers';
import {MapControls} from 'reducers';

interface SplitMapButtonIcons {
delete: ComponentType<any>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/toggle-3d-button.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {MapControls} from '../../reducers';
import {MapControls} from 'reducers';

interface Toggle3dButtonIcons {
cube: ComponentType<any>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/export-image-modal.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FunctionComponent} from 'react';
import {SetExportImageSettingUpdaterAction} from '../../actions';
import {ExportImage} from '../../reducers';
import {ExportImage} from 'reducers';
import {IntlShape} from 'react-intl';

export type ExportImageModalProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/save-map-modal.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {Provider} from '../../cloud-providers';
import {MapInfo, ExportImage} from '../../reducers';
import {MapInfo, ExportImage} from 'reducers';
import {
setMapInfo
} from '../../actions';
Expand Down
2 changes: 1 addition & 1 deletion src/components/side-panel.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ComponentType} from 'react';
import {Datasets, Filter, InteractionConfig, MapStyle} from '../reducers';
import {Datasets, Filter, InteractionConfig, MapStyle} from 'reducers';
import {Layer, LayerClassesType} from '../layers';

import * as MapStyleActions from 'actions/map-style-actions';
Expand Down
2 changes: 1 addition & 1 deletion src/layers/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RGBColor, RGBAColor, GpuFilter, MapState, Field, Filter, Datasets} from '../reducers';
import {RGBColor, RGBAColor, GpuFilter, MapState, Field, Filter, Datasets} from 'reducers';
import {LayerTextLabel, ColorRange, ColorUI, VisConfigRange} from './layer-factory';

export {LAYER_VIS_CONFIGS, LayerVisConfig} from './layer-factory';
Expand Down
2 changes: 1 addition & 1 deletion src/layers/trip-layer/trip-utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {Field} from '../../reducers';
import {Field} from 'reducers';

export const containValidTime: (timestamps: string[]) => Field | null;
25 changes: 0 additions & 25 deletions src/reducers/core.d.ts

This file was deleted.

38 changes: 26 additions & 12 deletions src/reducers/core.js → src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ import {providerStateReducerFactory} from './provider-state';

import composers from './composers';

/**
* @type {typeof import('./core').combineReducers_}
*/
const combineReducers_ = combineReducers;
import {VisState} from './vis-state-updaters';
import {MapState} from './map-state-updaters';
import {MapStyle} from './map-style-updaters';
import {ProviderState} from './provider-state-updaters';
import {UiState} from './ui-state-updaters';

export type KeplerGlState = {
visState: VisState;
mapState: MapState;
mapStyle: MapStyle;
uiState: UiState;
providerState: ProviderState;
};

const combined = (initialState = {}) =>
combineReducers_({
const combined = (initialState: Partial<KeplerGlState> = {}) =>
combineReducers({
visState: visStateReducerFactory(initialState.visState),
mapState: mapStateReducerFactory(initialState.mapState),
mapStyle: mapStyleReducerFactory(initialState.mapStyle),
uiState: uiStateReducerFactory(initialState.uiState),
providerState: providerStateReducerFactory(initialState.providerState)
});

export const coreReducerFactory = (initialState = {}) => (state, action) => {
export const coreReducerFactory = (initialState: Partial<KeplerGlState> = {}) => (
state,
action
) => {
if (composers[action.type]) {
return composers[action.type](state, action);
}
Expand All @@ -58,7 +70,7 @@ export default coreReducerFactory();
* @param {*} reduxState
* @public
*/
export const mapStateLens = reduxState => ({mapState: reduxState.mapState});
export const mapStateLens = (reduxState: KeplerGlState) => ({mapState: reduxState.mapState});

/**
* Connect subreducer `mapStyle`, used with `injectComponents`. Learn more at
Expand All @@ -67,7 +79,7 @@ export const mapStateLens = reduxState => ({mapState: reduxState.mapState});
* @param {*} reduxState
* @public
*/
export const mapStyleLens = reduxState => ({mapStyle: reduxState.mapStyle});
export const mapStyleLens = (reduxState: KeplerGlState) => ({mapStyle: reduxState.mapStyle});

/**
* Connect subreducer `visState`, used with `injectComponents`. Learn more at
Expand All @@ -76,7 +88,7 @@ export const mapStyleLens = reduxState => ({mapStyle: reduxState.mapStyle});
* @param {*} reduxState
* @public
*/
export const visStateLens = reduxState => ({visState: reduxState.visState});
export const visStateLens = (reduxState: KeplerGlState) => ({visState: reduxState.visState});

/**
* Connect subreducer `uiState`, used with `injectComponents`. Learn more at
Expand All @@ -85,7 +97,7 @@ export const visStateLens = reduxState => ({visState: reduxState.visState});
* @param {*} reduxState
* @public
*/
export const uiStateLens = reduxState => ({uiState: reduxState.uiState});
export const uiStateLens = (reduxState: KeplerGlState) => ({uiState: reduxState.uiState});

/**
* Connect subreducer `providerState`, used with `injectComponents`. Learn more at
Expand All @@ -94,4 +106,6 @@ export const uiStateLens = reduxState => ({uiState: reduxState.uiState});
* @param {*} reduxState
* @public
*/
export const providerStateLens = reduxState => ({providerState: reduxState.providerState});
export const providerStateLens = (reduxState: KeplerGlState) => ({
providerState: reduxState.providerState
});
119 changes: 1 addition & 118 deletions src/reducers/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1 @@
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Root Reducer, used to register, and remove core reducers of each instance
// export {default} from './root';
// export {default as keplerGlReducer} from './root';

// Core Reducer
export {
default as keplerGlReducerCore,
visStateLens,
mapStateLens,
uiStateLens,
mapStyleLens
} from './core';

// Each individual reducer
// export {default as visStateReducer} from './vis-state';
// export {default as mapStateReducer} from './map-state';
// export {default as mapStyleReducer} from './map-style';

// reducer updaters
export * as visStateUpdaters from './vis-state-updaters';
export * as mapStateUpdaters from './map-state-updaters';
export * as mapStyleUpdaters from './map-style-updaters';
export * as uiStateUpdaters from './ui-state-updaters';

// This will be deprecated
export * as combineUpdaters from './combined-updaters';
export * as combinedUpdaters from './combined-updaters';

// reducer merges
export * as visStateMergers from './vis-state-merger';

// export types
export {
AnimationConfig,
Brush,
Coordinate,
Dataset,
Datasets,
Editor,
Feature,
FeatureValue,
Field,
FieldDomain,
FieldPair,
Filter,
FilterBase,
FilterRecord,
Geocoder,
GpuFilter,
HistogramBin,
InteractionConfig,
LineChart,
MapInfo,
MultiSelectFieldDomain,
MultiSelectFilter,
PolygonFilter,
RangeFieldDomain,
RangeFilter,
SelectFieldDomain,
SelectFilter,
SplitMap,
TimeRangeFieldDomain,
TimeRangeFilter,
TooltipInfo,
VisState
} from './vis-state-updaters';

export {
BaseMapStyle,
InputStyle,
LayerGroup,
MapboxStyleUrl,
MapStyle,
MapStyles,
VisibleLayerGroups
} from './map-style-updaters';

export {
Bounds,
MapState,
Viewport
} from './map-state-updaters';

export {
ExportData,
ExportHtml,
ExportImage,
ExportJson,
ExportMap,
LoadFiles,
Locale,
MapControl,
MapControls,
Notifications,
UiState
} from './ui-state-updaters';

export * from './types';
// TODO: Delete this file
63 changes: 63 additions & 0 deletions src/reducers/index.js → src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,66 @@ export * as visStateMergers from './vis-state-merger';

// Helpers
export * from './composer-helpers';

// export types
export type {
AnimationConfig,
Brush,
Coordinate,
Datasets,
Editor,
Feature,
FeatureValue,
FieldDomain,
Filter,
FilterBase,
Geocoder,
HistogramBin,
InteractionConfig,
LineChart,
MapInfo,
MultiSelectFieldDomain,
MultiSelectFilter,
PolygonFilter,
RangeFieldDomain,
RangeFilter,
SelectFieldDomain,
SelectFilter,
SplitMap,
TimeRangeFieldDomain,
TimeRangeFilter,
TooltipInfo,
VisState
} from './vis-state-updaters';

export type {
BaseMapStyle,
InputStyle,
LayerGroup,
MapboxStyleUrl,
MapStyle,
MapStyles,
VisibleLayerGroups
} from './map-style-updaters';

export type {
Bounds,
MapState,
Viewport
} from './map-state-updaters';

export type {
ExportData,
ExportHtml,
ExportImage,
ExportJson,
ExportMap,
LoadFiles,
Locale,
MapControl,
MapControls,
Notifications,
UiState
} from './ui-state-updaters';

export * from './types';
5 changes: 3 additions & 2 deletions src/reducers/root.js → src/reducers/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ export function provideInitialState(initialState) {
[ActionTypes.RENAME_ENTRY]: handleRenameEntry
};

// @ts-ignore
// TODO: Understand why the Lint sees an error here, while the IDE does not.
// @ts-expect-error
return handleActions(handlers, initialCoreState)(state, action);
};
}

const _keplerGlReducer = provideInitialState();
const _keplerGlReducer = provideInitialState(initialCoreState);

function mergeInitialState(saved = {}, provided = {}) {
const keys = ['mapState', 'mapStyle', 'visState', 'uiState'];
Expand Down

0 comments on commit e36cac5

Please sign in to comment.