mirror of
				https://github.com/reduxjs/redux-devtools.git
				synced 2025-10-31 16:07:45 +03:00 
			
		
		
		
	* fix(deps): update dependency immutable to v5 * Updates * Updates * Updates * Fix lint --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import jsan from 'jsan';
 | |
| import { immutableSerialize } from '@redux-devtools/serialize';
 | |
| import { Action } from 'redux';
 | |
| import type Immutable from 'immutable';
 | |
| import { PerformAction } from '@redux-devtools/core';
 | |
| 
 | |
| interface State {
 | |
|   actionsById: { [actionId: number]: PerformAction<Action<string>> };
 | |
|   computedStates: { state: unknown; error?: string }[];
 | |
|   committedState?: unknown;
 | |
| }
 | |
| 
 | |
| export function importState(
 | |
|   state: string,
 | |
|   {
 | |
|     serialize,
 | |
|   }: {
 | |
|     serialize?: {
 | |
|       immutable?: typeof Immutable;
 | |
|       refs?: (new (data: any) => unknown)[] | null;
 | |
|       reviver?: (key: string, value: unknown) => unknown;
 | |
|     };
 | |
|   },
 | |
| ) {
 | |
|   if (!state) return undefined;
 | |
|   let parse = jsan.parse;
 | |
|   if (serialize) {
 | |
|     if (serialize.immutable) {
 | |
|       parse = (v) =>
 | |
|         jsan.parse(
 | |
|           v,
 | |
|           immutableSerialize(serialize.immutable!, serialize.refs).reviver,
 | |
|         );
 | |
|     } else if (serialize.reviver) {
 | |
|       parse = (v) => jsan.parse(v, serialize.reviver);
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   let preloadedState: State | undefined;
 | |
|   let nextLiftedState: State = parse(state) as State;
 | |
|   if (
 | |
|     (
 | |
|       nextLiftedState as unknown as {
 | |
|         payload?: string;
 | |
|         preloadedState?: string;
 | |
|       }
 | |
|     ).payload
 | |
|   ) {
 | |
|     if (
 | |
|       (
 | |
|         nextLiftedState as unknown as {
 | |
|           payload: string;
 | |
|           preloadedState?: string;
 | |
|         }
 | |
|       ).preloadedState
 | |
|     )
 | |
|       preloadedState = parse(
 | |
|         (
 | |
|           nextLiftedState as unknown as {
 | |
|             payload: string;
 | |
|             preloadedState: string;
 | |
|           }
 | |
|         ).preloadedState,
 | |
|       ) as State;
 | |
|     nextLiftedState = parse(
 | |
|       (
 | |
|         nextLiftedState as unknown as {
 | |
|           payload: string;
 | |
|         }
 | |
|       ).payload,
 | |
|     ) as State;
 | |
|   }
 | |
| 
 | |
|   return { nextLiftedState, preloadedState };
 | |
| }
 |