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:
@ -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,
|
||||
});
|
||||
};
|
||||
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@ -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 });
|
||||
|
||||
@ -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 });
|
||||
};
|
||||
Reference in New Issue
Block a user