kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
90 lines (84 loc) • 4.11 kB
JavaScript
// 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.
import {createAction} from 'redux-actions';
import ActionTypes from 'constants/action-types';
/**
*
* Add a new kepler.gl instance in `keplerGlReducer`. This action is called under-the-hood when a `KeplerGl` component is **mounted** to the dom.
* Note that if you dispatch actions such as adding data to a kepler.gl instance before the React component is mounted, the action will not be
* performed. Instance reducer can only handle actions when it is instantiated.
* @memberof rootActions
* @param {Object} payload
* @param {string} payload.id - ***required** The id of the instance
* @param {boolean} payload.mint - Whether to use a fresh empty state, when `mint: true` it will *always* load a fresh state when the component is re-mounted.
* When `mint: false` it will register with existing instance state under the same `id`, when the component is unmounted then mounted again. Default: `true`
* @param {string} payload.mapboxApiAccessToken - mapboxApiAccessToken to be saved in `map-style` reducer.
* @param {string} payload.mapboxApiUrl - mapboxApiUrl to be saved in `map-style` reducer.
* @param {Boolean} payload.mapStylesReplaceDefault - mapStylesReplaceDefault to be saved in `map-style` reducer.
* @public
*/
export const registerEntry = createAction(
ActionTypes.REGISTER_ENTRY,
({id, mint, mapboxApiAccessToken, mapboxApiUrl, mapStylesReplaceDefault}) => ({
id,
mint,
mapboxApiAccessToken,
mapboxApiUrl,
mapStylesReplaceDefault
})
);
/**
*
* Delete an instance from `keplerGlReducer`. This action is called under-the-hood when a `KeplerGl` component is **un-mounted** to the dom.
* If `mint` is set to be `true` in the component prop, the instance state will be deleted from the root reducer. Otherwise, the root reducer will keep
* the instance state and later transfer it to a newly mounted component with the same `id`
* @memberof rootActions
* @param {string} id - the id of the instance to be deleted
* @public
*/
export const deleteEntry = createAction(ActionTypes.DELETE_ENTRY, id => id);
/**
*
* Rename an instance in the root reducer, keep its entire state
*
* @memberof rootActions
* @param {string} oldId - ***required** old id
* @param {string} newId - ***required** new id
* @public
*/
export const renameEntry = createAction(ActionTypes.RENAME_ENTRY, (oldId, newId) => ({
oldId,
newId
}));
/**
* This declaration is needed to group actions in docs
*/
/**
* Root actions managers adding and removing instances in root reducer.
* Under-the-hood, when a `KeplerGl` component is mounted or unmounted,
* it will automatically calls these actions to add itself to the root reducer.
* However, sometimes the data is ready before the component is registered in the reducer,
* in this case, you can manually call these actions or the corresponding updater to add it to the reducer.
*
* @public
*/
/* eslint-disable no-unused-vars */
const rootActions = null;
/* eslint-enable no-unused-vars */