Skip to content

Commit

Permalink
Expand typings to include hash stuff and expand the State type defini…
Browse files Browse the repository at this point in the history
…tion more.
  • Loading branch information
stacey-gammon committed Oct 16, 2018
1 parent 5458371 commit 09db49a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/ui/public/state_management/state.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
* under the License.
*/

export type State = Record<string, any>;
export interface State {
[key: string]: any;
translateHashToRison: (
stateHashOrRison: string | string[] | undefined
) => string | string[] | undefined;
getQueryParamName: () => string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
* under the License.
*/

export function getUnhashableStatesProvider(getAppState, globalState) {
return function getUnhashableStates() {
import { AppState } from '../app_state';
import { GlobalState } from '../global_state';
import { State } from '../state';

export function getUnhashableStatesProvider(getAppState: () => AppState, globalState: GlobalState) {
return function getUnhashableStates(): State[] {
return [getAppState(), globalState].filter(Boolean);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
*/

import { mapValues } from 'lodash';
import { ParsedUrlQuery } from 'querystring';
import { State } from '../state';

export function unhashQueryString(parsedQueryString, states) {
/**
* Takes in a parsed url query and state objects, finding the state objects that match the query parameters and expanding
* the hashed state. For example, a url query string like '?_a=@12353&_g=@19028df' will become
* '?_a=[expanded app state here]&_g=[expanded global state here]. This is used when storeStateInSessionStorage is turned on.
*/
export function unhashQueryString(
parsedQueryString: ParsedUrlQuery,
states: State[]
): ParsedUrlQuery {
return mapValues(parsedQueryString, (val, key) => {
const state = states.find(s => key === s.getQueryParamName());
return state ? state.translateHashToRison(val) : val;
Expand Down

0 comments on commit 09db49a

Please sign in to comment.