redux#DeepPartial TypeScript Examples

The following examples show how to use redux#DeepPartial. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From pipeline-editor with Apache License 2.0 7 votes vote down vote up
export function deepmerge<T>(target: T, source: DeepPartial<T>) {
  const output = { ...target };

  if (isPlainObject(target) && isPlainObject(source)) {
    for (let _key of Object.keys(source)) {
      const key = _key as keyof DeepPartial<T>;

      const tVal = target[key];
      const sVal = source[key] as DeepPartial<typeof tVal>;

      if (sVal !== undefined) {
        if (isPlainObject(sVal) && tVal !== undefined) {
          output[key] = deepmerge<typeof tVal>(tVal, sVal);
        } else {
          output[key] = sVal as T[keyof T];
        }
      }
    }
  }

  return output;
}
Example #2
Source File: index.tsx    From pipeline-editor with Apache License 2.0 6 votes vote down vote up
function mergeThemes(systemInfo: {
  mode: "dark" | "light";
  platform: "mac" | "win" | "other";
}) {
  return (overides: Partial<Theme>): Theme => {
    return deepmerge<Theme>(
      { ...defaultTheme, ...systemInfo },
      overides as DeepPartial<Theme>
    );
  };
}
Example #3
Source File: index.tsx    From pipeline-editor with Apache License 2.0 5 votes vote down vote up
export function createTheme(theme: DeepPartial<Theme>) {
  return theme;
}
Example #4
Source File: index.tsx    From pipeline-editor with Apache License 2.0 5 votes vote down vote up
ThemeProvider: React.FC<{ theme: DeepPartial<Theme> }> = ({
  theme,
  children,
}) => {
  return (
    <StyledThemeProvider theme={theme as any}>{children}</StyledThemeProvider>
  );
}
Example #5
Source File: index.tsx    From pybricks-code with MIT License 5 votes vote down vote up
public updateState(state: DeepPartial<RootState>): void {
        for (const key of Object.keys(state) as Array<keyof RootState>) {
            // @ts-expect-error: writing to readonly for testing
            this.state[key] = { ...this.state[key], ...state[key] };
        }
    }
Example #6
Source File: store.ts    From beancount-mobile with MIT License 5 votes vote down vote up
preloadedState: DeepPartial<AppState> = {
  base: {
    locale: Locatization.locale,
    currentTheme: colorMode as Mode,
  },
}