mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Remove more ovbious ramda helper usages
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { AsyncThunkPayloadCreator } from '@reduxjs/toolkit';
|
||||
import { createAsyncThunk as baseCreateAsyncThunk } from '@reduxjs/toolkit';
|
||||
import { identity } from 'ramda';
|
||||
import type { ShlinkState } from '../../container/types';
|
||||
|
||||
export const createAsyncThunk = <Returned, ThunkArg>(
|
||||
@@ -9,5 +8,5 @@ export const createAsyncThunk = <Returned, ThunkArg>(
|
||||
) => baseCreateAsyncThunk(
|
||||
typePrefix,
|
||||
payloadCreator,
|
||||
{ serializeError: identity },
|
||||
{ serializeError: (e) => e },
|
||||
);
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { compare } from 'compare-versions';
|
||||
import { identity, isEmpty, isNil, memoizeWith } from 'ramda';
|
||||
import { memoizeWith } from 'ramda';
|
||||
|
||||
export type Empty = null | undefined | '' | never[];
|
||||
|
||||
const hasValue = <T>(value: T | Empty): value is T => !isNil(value) && !isEmpty(value);
|
||||
const isEmpty = (value: Exclude<any, undefined | null>): boolean => (
|
||||
(Array.isArray(value) && value.length === 0)
|
||||
|| (typeof value === 'string' && value === '')
|
||||
|| (typeof value === 'object' && Object.keys(value).length === 0)
|
||||
);
|
||||
|
||||
export const hasValue = <T>(value: T | Empty): value is T => value !== undefined && value !== null && !isEmpty(value);
|
||||
|
||||
type SemVerPatternFragment = `${bigint | '*'}`;
|
||||
|
||||
@@ -29,7 +35,7 @@ export const versionMatch = (versionToMatch: SemVer | Empty, { maxVersion, minVe
|
||||
return matchesMaxVersion && matchesMinVersion;
|
||||
};
|
||||
|
||||
const versionIsValidSemVer = memoizeWith(identity, (version: string): version is SemVer => {
|
||||
const versionIsValidSemVer = memoizeWith((v) => v, (version: string): version is SemVer => {
|
||||
try {
|
||||
return compare(version, version, '=');
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { pipe, range } from 'ramda';
|
||||
import { range } from 'ramda';
|
||||
import type { SyntheticEvent } from 'react';
|
||||
|
||||
type Optional<T> = T | null | undefined;
|
||||
|
||||
export type OptionalString = Optional<string>;
|
||||
|
||||
export const handleEventPreventingDefault = <T>(handler: () => T) => pipe(
|
||||
(e: SyntheticEvent) => e.preventDefault(),
|
||||
handler,
|
||||
);
|
||||
export const handleEventPreventingDefault = <T>(handler: () => T) => (e: SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
handler();
|
||||
};
|
||||
|
||||
export const rangeOf = <T>(size: number, mappingFn: (value: number) => T, startAt = 1): T[] =>
|
||||
range(startAt, size + 1).map(mappingFn);
|
||||
|
||||
Reference in New Issue
Block a user