Refactor Field Inputs (#3658)

* Rename field to record-field folder

* Simplify FieldInput

* Fix perfs

* Fixes

* Fixes

* Fix tests

* Fix tests
This commit is contained in:
Charles Bochet
2024-01-27 23:42:39 +01:00
committed by GitHub
parent d6f117c688
commit ada8f55574
228 changed files with 975 additions and 1037 deletions

View File

@ -0,0 +1,30 @@
import {
GetCallback,
GetRecoilValue,
Loadable,
RecoilValue,
selectorFamily,
WrappedValue,
} from 'recoil';
import { StateScopeMapKey } from '@/ui/utilities/recoil-scope/scopes-internal/types/StateScopeMapKey';
type SelectorGetter<T, P> = (
param: P,
) => (opts: {
get: GetRecoilValue;
getCallback: GetCallback;
}) => Promise<T> | RecoilValue<T> | Loadable<T> | WrappedValue<T> | T;
export const createSelectorReadOnlyScopeMap = <ValueType>({
key,
get,
}: {
key: string;
get: SelectorGetter<ValueType, StateScopeMapKey>;
}) => {
return selectorFamily<ValueType, StateScopeMapKey>({
key,
get,
});
};

View File

@ -1,9 +1,12 @@
import {
DefaultValue,
GetCallback,
GetRecoilValue,
Loadable,
RecoilValue,
ResetRecoilState,
selectorFamily,
SetRecoilState,
WrappedValue,
} from 'recoil';
@ -16,15 +19,25 @@ type SelectorGetter<T, P> = (
getCallback: GetCallback;
}) => Promise<T> | RecoilValue<T> | Loadable<T> | WrappedValue<T> | T;
type SelectorSetter<T, P> = (
param: P,
) => (
opts: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState },
newValue: T | DefaultValue,
) => void;
export const createSelectorScopeMap = <ValueType>({
key,
get,
set,
}: {
key: string;
get: SelectorGetter<ValueType, StateScopeMapKey>;
set: SelectorSetter<ValueType, StateScopeMapKey>;
}) => {
return selectorFamily<ValueType, StateScopeMapKey>({
key,
get,
set,
});
};

View File

@ -1,11 +1,9 @@
import { RecoilValueReadOnly } from 'recoil';
import { RecoilState } from 'recoil';
import { StateScopeMapKey } from '@/ui/utilities/recoil-scope/scopes-internal/types/StateScopeMapKey';
export const getSelector = <StateType>(
stateScopeMap: (
stateScopeMapKey: StateScopeMapKey,
) => RecoilValueReadOnly<StateType>,
stateScopeMap: (stateScopeMapKey: StateScopeMapKey) => RecoilState<StateType>,
scopeId: string,
) => {
return () => stateScopeMap({ scopeId });

View File

@ -0,0 +1,12 @@
import { RecoilValueReadOnly } from 'recoil';
import { StateScopeMapKey } from '@/ui/utilities/recoil-scope/scopes-internal/types/StateScopeMapKey';
export const getSelectorReadOnly = <StateType>(
stateScopeMap: (
stateScopeMapKey: StateScopeMapKey,
) => RecoilValueReadOnly<StateType>,
scopeId: string,
) => {
return () => stateScopeMap({ scopeId });
};