Removed all v2 in naming of state management logic (#13675)
This PR removes any V2 naming in state management logic and some minor utils and hooks. It has a lot of changes but nearly all of them were made by the rename functionality of vscode which is deterministic, so it shouldn't introduce any regression. QA has been made on this PR on the main features of the app without any noticeable issue. Also renamed some other v2 naming related items : - TextInputV2 => TextInput - TextInput => SettingsTextInput - ObjectFilterDropdownFilterSelectMenuItemV2 => ObjectFilterDropdownFilterSelectMenuItem - useInitDraftValueV2 => useInitDraftValue - useOpenRecordTableCellV2 => useOpenRecordTableCell
This commit is contained in:
+2
-2
@@ -3,7 +3,7 @@ import { RecoilRoot } from 'recoil';
|
||||
|
||||
import { useClickOutsideListener } from '@/ui/utilities/pointer-event/hooks/useClickOutsideListener';
|
||||
import { clickOutsideListenerIsActivatedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsActivatedComponentState';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
||||
|
||||
const componentId = 'componentId';
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('useClickOutsideListener', () => {
|
||||
() => {
|
||||
return {
|
||||
useClickOutside: useClickOutsideListener(componentId),
|
||||
isActivated: useRecoilComponentValueV2(
|
||||
isActivated: useRecoilComponentValue(
|
||||
clickOutsideListenerIsActivatedComponentState,
|
||||
componentId,
|
||||
),
|
||||
|
||||
+6
-7
@@ -2,17 +2,16 @@ import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { clickOutsideListenerIsActivatedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsActivatedComponentState';
|
||||
import { clickOutsideListenerMouseDownHappenedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerMouseDownHappenedComponentState';
|
||||
import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2';
|
||||
import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState';
|
||||
|
||||
export const useClickOutsideListener = (instanceId: string) => {
|
||||
const clickOutsideListenerIsActivatedState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
clickOutsideListenerIsActivatedComponentState,
|
||||
instanceId,
|
||||
);
|
||||
const clickOutsideListenerIsActivatedState = useRecoilComponentCallbackState(
|
||||
clickOutsideListenerIsActivatedComponentState,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
const clickOutsideListenerMouseDownHappenedState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
useRecoilComponentCallbackState(
|
||||
clickOutsideListenerMouseDownHappenedComponentState,
|
||||
instanceId,
|
||||
);
|
||||
|
||||
+7
-8
@@ -1,7 +1,7 @@
|
||||
import { clickOutsideListenerIsActivatedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsActivatedComponentState';
|
||||
import { clickOutsideListenerIsMouseDownInsideComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsMouseDownInsideComponentState';
|
||||
import { clickOutsideListenerMouseDownHappenedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerMouseDownHappenedComponentState';
|
||||
import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2';
|
||||
import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
@@ -24,17 +24,16 @@ export const useListenClickOutside = <T extends Element>({
|
||||
enabled = true,
|
||||
}: ClickOutsideListenerProps<T>) => {
|
||||
const clickOutsideListenerIsMouseDownInsideState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
useRecoilComponentCallbackState(
|
||||
clickOutsideListenerIsMouseDownInsideComponentState,
|
||||
listenerId,
|
||||
);
|
||||
const clickOutsideListenerIsActivatedState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
clickOutsideListenerIsActivatedComponentState,
|
||||
listenerId,
|
||||
);
|
||||
const clickOutsideListenerIsActivatedState = useRecoilComponentCallbackState(
|
||||
clickOutsideListenerIsActivatedComponentState,
|
||||
listenerId,
|
||||
);
|
||||
const clickOutsideListenerMouseDownHappenedState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
useRecoilComponentCallbackState(
|
||||
clickOutsideListenerMouseDownHappenedComponentState,
|
||||
listenerId,
|
||||
);
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ClickOutsideListenerComponentInstanceContext } from '@/ui/utilities/pointer-event/states/contexts/ClickOutsideListenerComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const clickOutsideListenerIsActivatedComponentState =
|
||||
createComponentStateV2<boolean>({
|
||||
createComponentState<boolean>({
|
||||
key: 'clickOutsideListenerIsActivatedComponentState',
|
||||
defaultValue: true,
|
||||
componentInstanceContext: ClickOutsideListenerComponentInstanceContext,
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ClickOutsideListenerComponentInstanceContext } from '@/ui/utilities/pointer-event/states/contexts/ClickOutsideListenerComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const clickOutsideListenerIsMouseDownInsideComponentState =
|
||||
createComponentStateV2<boolean>({
|
||||
createComponentState<boolean>({
|
||||
key: 'clickOutsideListenerIsMouseDownInsideComponentState',
|
||||
defaultValue: false,
|
||||
componentInstanceContext: ClickOutsideListenerComponentInstanceContext,
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ClickOutsideListenerComponentInstanceContext } from '@/ui/utilities/pointer-event/states/contexts/ClickOutsideListenerComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const clickOutsideListenerMouseDownHappenedComponentState =
|
||||
createComponentStateV2<boolean>({
|
||||
createComponentState<boolean>({
|
||||
key: 'clickOutsideListenerMouseDownHappenedComponentState',
|
||||
defaultValue: false,
|
||||
componentInstanceContext: ClickOutsideListenerComponentInstanceContext,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/sta
|
||||
import { scrollWrapperScrollBottomComponentState } from '@/ui/utilities/scroll/states/scrollWrapperScrollBottomComponentState';
|
||||
import { scrollWrapperScrollLeftComponentState } from '@/ui/utilities/scroll/states/scrollWrapperScrollLeftComponentState';
|
||||
import { scrollWrapperScrollTopComponentState } from '@/ui/utilities/scroll/states/scrollWrapperScrollTopComponentState';
|
||||
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';
|
||||
import { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';
|
||||
|
||||
const StyledScrollWrapper = styled.div`
|
||||
&.scroll-wrapper-x-enabled {
|
||||
@@ -35,17 +35,17 @@ export const ScrollWrapper = ({
|
||||
defaultEnableXScroll = true,
|
||||
defaultEnableYScroll = true,
|
||||
}: ScrollWrapperProps) => {
|
||||
const setScrollTop = useSetRecoilComponentStateV2(
|
||||
const setScrollTop = useSetRecoilComponentState(
|
||||
scrollWrapperScrollTopComponentState,
|
||||
componentInstanceId,
|
||||
);
|
||||
|
||||
const setScrollLeft = useSetRecoilComponentStateV2(
|
||||
const setScrollLeft = useSetRecoilComponentState(
|
||||
scrollWrapperScrollLeftComponentState,
|
||||
componentInstanceId,
|
||||
);
|
||||
|
||||
const setScrollBottom = useSetRecoilComponentStateV2(
|
||||
const setScrollBottom = useSetRecoilComponentState(
|
||||
scrollWrapperScrollBottomComponentState,
|
||||
componentInstanceId,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SCROLL_RESTORATION_TOP_THRESHOLD_PX } from '@/ui/utilities/scroll/constants/ScrollRestorationTopThreshold';
|
||||
import { scrollWrapperScrollTopComponentState } from '@/ui/utilities/scroll/states/scrollWrapperScrollTopComponentState';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
@@ -10,7 +10,7 @@ export const useScrollRestoration = (componentInstanceId: string) => {
|
||||
const storageKey = `scroll-${location.pathname}`;
|
||||
const [isRestoring, setIsRestoring] = useState(false);
|
||||
|
||||
const scrollTop = useRecoilComponentValueV2(
|
||||
const scrollTop = useRecoilComponentValue(
|
||||
scrollWrapperScrollTopComponentState,
|
||||
componentInstanceId,
|
||||
);
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/states/contexts/ScrollWrapperComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const scrollWrapperScrollBottomComponentState =
|
||||
createComponentStateV2<number>({
|
||||
createComponentState<number>({
|
||||
key: 'scrollWrapperScrollBottomComponentState',
|
||||
defaultValue: 0,
|
||||
componentInstanceContext: ScrollWrapperComponentInstanceContext,
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/states/contexts/ScrollWrapperComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const scrollWrapperScrollLeftComponentState =
|
||||
createComponentStateV2<number>({
|
||||
createComponentState<number>({
|
||||
key: 'scrollWrapperScrollLeftComponentState',
|
||||
defaultValue: 0,
|
||||
componentInstanceContext: ScrollWrapperComponentInstanceContext,
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/states/contexts/ScrollWrapperComponentInstanceContext';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
|
||||
export const scrollWrapperScrollTopComponentState =
|
||||
createComponentStateV2<number>({
|
||||
createComponentState<number>({
|
||||
key: 'scrollWrapperScrollTopComponentState',
|
||||
defaultValue: 0,
|
||||
componentInstanceContext: ScrollWrapperComponentInstanceContext,
|
||||
|
||||
+29
-29
@@ -1,69 +1,69 @@
|
||||
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilyReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelectorV2';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelectorV2';
|
||||
import { ComponentSelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentSelectorV2';
|
||||
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
|
||||
import { ComponentFamilyReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelector';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { ComponentReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelector';
|
||||
import { ComponentSelector } from '@/ui/utilities/state/component-state/types/ComponentSelector';
|
||||
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { RecoilState, RecoilValueReadOnly, SerializableParam } from 'recoil';
|
||||
|
||||
export function useRecoilComponentCallbackStateV2<ValueType>(
|
||||
componentState: ComponentStateV2<ValueType>,
|
||||
export function useRecoilComponentCallbackState<ValueType>(
|
||||
componentState: ComponentState<ValueType>,
|
||||
instanceIdFromProps?: string,
|
||||
): RecoilState<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<ValueType>(
|
||||
componentSelector: ComponentSelectorV2<ValueType>,
|
||||
export function useRecoilComponentCallbackState<ValueType>(
|
||||
componentSelector: ComponentSelector<ValueType>,
|
||||
instanceIdFromProps?: string,
|
||||
): RecoilState<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<ValueType>(
|
||||
componentReadOnlySelector: ComponentReadOnlySelectorV2<ValueType>,
|
||||
export function useRecoilComponentCallbackState<ValueType>(
|
||||
componentReadOnlySelector: ComponentReadOnlySelector<ValueType>,
|
||||
instanceIdFromProps?: string,
|
||||
): RecoilValueReadOnly<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<
|
||||
export function useRecoilComponentCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyState: ComponentFamilyStateV2<ValueType, FamilyKey>,
|
||||
componentFamilyState: ComponentFamilyState<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<
|
||||
export function useRecoilComponentCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilySelector: ComponentFamilySelectorV2<ValueType, FamilyKey>,
|
||||
componentFamilySelector: ComponentFamilySelector<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<
|
||||
export function useRecoilComponentCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyReadOnlySelector: ComponentFamilyReadOnlySelectorV2<
|
||||
componentFamilyReadOnlySelector: ComponentFamilyReadOnlySelector<
|
||||
ValueType,
|
||||
FamilyKey
|
||||
>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilValueReadOnly<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<
|
||||
export function useRecoilComponentCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyState: ComponentFamilyStateV2<ValueType, FamilyKey>,
|
||||
componentFamilyState: ComponentFamilyState<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentCallbackStateV2<
|
||||
ComponentState extends
|
||||
| ComponentStateV2<ValueType>
|
||||
| ComponentSelectorV2<ValueType>
|
||||
| ComponentReadOnlySelectorV2<ValueType>
|
||||
| ComponentFamilyStateV2<ValueType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey>,
|
||||
export function useRecoilComponentCallbackState<
|
||||
InferedComponentState extends
|
||||
| ComponentState<ValueType>
|
||||
| ComponentSelector<ValueType>
|
||||
| ComponentReadOnlySelector<ValueType>
|
||||
| ComponentFamilyState<ValueType, FamilyKey>
|
||||
| ComponentFamilySelector<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelector<ValueType, FamilyKey>,
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam = never,
|
||||
>(
|
||||
componentState: ComponentState,
|
||||
componentState: InferedComponentState,
|
||||
instanceIdFromProps?: string,
|
||||
):
|
||||
| RecoilState<ValueType>
|
||||
+15
-15
@@ -1,48 +1,48 @@
|
||||
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilyReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelectorV2';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentFamilyReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelector';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { useCallback } from 'react';
|
||||
import { RecoilState, RecoilValueReadOnly, SerializableParam } from 'recoil';
|
||||
|
||||
export function useRecoilComponentFamilyCallbackStateV2<
|
||||
export function useRecoilComponentFamilyCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyState: ComponentFamilyStateV2<ValueType, FamilyKey>,
|
||||
componentFamilyState: ComponentFamilyState<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentFamilyCallbackStateV2<
|
||||
export function useRecoilComponentFamilyCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilySelector: ComponentFamilySelectorV2<ValueType, FamilyKey>,
|
||||
componentFamilySelector: ComponentFamilySelector<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentFamilyCallbackStateV2<
|
||||
export function useRecoilComponentFamilyCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyReadOnlySelector: ComponentFamilyReadOnlySelectorV2<
|
||||
componentFamilyReadOnlySelector: ComponentFamilyReadOnlySelector<
|
||||
ValueType,
|
||||
FamilyKey
|
||||
>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilValueReadOnly<ValueType>;
|
||||
export function useRecoilComponentFamilyCallbackStateV2<
|
||||
export function useRecoilComponentFamilyCallbackState<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentFamilyState: ComponentFamilyStateV2<ValueType, FamilyKey>,
|
||||
componentFamilyState: ComponentFamilyState<ValueType, FamilyKey>,
|
||||
instanceIdFromProps?: string,
|
||||
): (familyKey: FamilyKey) => RecoilState<ValueType>;
|
||||
export function useRecoilComponentFamilyCallbackStateV2<
|
||||
export function useRecoilComponentFamilyCallbackState<
|
||||
ComponentState extends
|
||||
| ComponentFamilyStateV2<ValueType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey>,
|
||||
| ComponentFamilyState<ValueType, FamilyKey>
|
||||
| ComponentFamilySelector<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelector<ValueType, FamilyKey>,
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam = never,
|
||||
>(
|
||||
+5
-5
@@ -1,16 +1,16 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SerializableParam, useRecoilState } from 'recoil';
|
||||
|
||||
export const useRecoilComponentFamilyStateV2 = <
|
||||
export const useRecoilComponentFamilyState = <
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentState:
|
||||
| ComponentFamilyStateV2<StateType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<StateType, FamilyKey>,
|
||||
| ComponentFamilyState<StateType, FamilyKey>
|
||||
| ComponentFamilySelector<StateType, FamilyKey>,
|
||||
familyKey: FamilyKey,
|
||||
instanceIdFromProps?: string,
|
||||
) => {
|
||||
+14
-14
@@ -1,29 +1,29 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilyReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelectorV2';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentFamilyReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelector';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SerializableParam, useRecoilValue } from 'recoil';
|
||||
|
||||
export const useRecoilComponentFamilyValueV2 = <
|
||||
export const useRecoilComponentFamilyValue = <
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentStateV2:
|
||||
| ComponentFamilyStateV2<StateType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<StateType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelectorV2<StateType, FamilyKey>,
|
||||
componentState:
|
||||
| ComponentFamilyState<StateType, FamilyKey>
|
||||
| ComponentFamilySelector<StateType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelector<StateType, FamilyKey>,
|
||||
familyKey: FamilyKey,
|
||||
instanceIdFromProps?: string,
|
||||
): StateType => {
|
||||
const instanceContext = globalComponentInstanceContextMap.get(
|
||||
componentStateV2.key,
|
||||
componentState.key,
|
||||
);
|
||||
|
||||
if (!instanceContext) {
|
||||
throw new Error(
|
||||
`Instance context for key "${componentStateV2.key}" is not defined`,
|
||||
`Instance context for key "${componentState.key}" is not defined`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,20 +32,20 @@ export const useRecoilComponentFamilyValueV2 = <
|
||||
instanceIdFromProps,
|
||||
);
|
||||
|
||||
switch (componentStateV2.type) {
|
||||
switch (componentState.type) {
|
||||
case 'ComponentFamilyState': {
|
||||
return useRecoilValue(
|
||||
componentStateV2.atomFamily({ familyKey, instanceId }),
|
||||
componentState.atomFamily({ familyKey, instanceId }),
|
||||
);
|
||||
}
|
||||
case 'ComponentFamilySelector': {
|
||||
return useRecoilValue(
|
||||
componentStateV2.selectorFamily({ familyKey, instanceId }),
|
||||
componentState.selectorFamily({ familyKey, instanceId }),
|
||||
);
|
||||
}
|
||||
case 'ComponentFamilyReadOnlySelector': {
|
||||
return useRecoilValue(
|
||||
componentStateV2.selectorFamily({ familyKey, instanceId }),
|
||||
componentState.selectorFamily({ familyKey, instanceId }),
|
||||
);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
|
||||
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
export const useRecoilComponentStateV2 = <StateType>(
|
||||
componentState: ComponentStateV2<StateType>,
|
||||
export const useRecoilComponentState = <StateType>(
|
||||
componentState: ComponentState<StateType>,
|
||||
instanceIdFromProps?: string,
|
||||
) => {
|
||||
const componentInstanceContext = globalComponentInstanceContextMap.get(
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelector';
|
||||
import { ComponentSelector } from '@/ui/utilities/state/component-state/types/ComponentSelector';
|
||||
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { RecoilState, RecoilValueReadOnly, useRecoilValue } from 'recoil';
|
||||
|
||||
export const useRecoilComponentValue = <StateType>(
|
||||
componentState:
|
||||
| ComponentState<StateType>
|
||||
| ComponentSelector<StateType>
|
||||
| ComponentReadOnlySelector<StateType>,
|
||||
instanceIdFromProps?: string,
|
||||
) => {
|
||||
const instanceContext = globalComponentInstanceContextMap.get(
|
||||
componentState.key,
|
||||
);
|
||||
|
||||
if (!instanceContext) {
|
||||
throw new Error(
|
||||
`Instance context for key "${componentState.key}" is not defined`,
|
||||
);
|
||||
}
|
||||
|
||||
const instanceId = useAvailableComponentInstanceIdOrThrow(
|
||||
instanceContext,
|
||||
instanceIdFromProps,
|
||||
);
|
||||
|
||||
let state: RecoilState<StateType> | RecoilValueReadOnly<StateType>;
|
||||
|
||||
if (componentState.type === 'ComponentState') {
|
||||
state = componentState.atomFamily({ instanceId });
|
||||
} else if (
|
||||
componentState.type === 'ComponentSelector' ||
|
||||
componentState.type === 'ComponentReadOnlySelector'
|
||||
) {
|
||||
state = componentState.selectorFamily({ instanceId });
|
||||
} else {
|
||||
throw new Error('Invalid component state type');
|
||||
}
|
||||
|
||||
return useRecoilValue(state);
|
||||
};
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelectorV2';
|
||||
import { ComponentSelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentSelectorV2';
|
||||
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { RecoilState, RecoilValueReadOnly, useRecoilValue } from 'recoil';
|
||||
|
||||
export const useRecoilComponentValueV2 = <StateType>(
|
||||
componentStateV2:
|
||||
| ComponentStateV2<StateType>
|
||||
| ComponentSelectorV2<StateType>
|
||||
| ComponentReadOnlySelectorV2<StateType>,
|
||||
instanceIdFromProps?: string,
|
||||
) => {
|
||||
const instanceContext = globalComponentInstanceContextMap.get(
|
||||
componentStateV2.key,
|
||||
);
|
||||
|
||||
if (!instanceContext) {
|
||||
throw new Error(
|
||||
`Instance context for key "${componentStateV2.key}" is not defined`,
|
||||
);
|
||||
}
|
||||
|
||||
const instanceId = useAvailableComponentInstanceIdOrThrow(
|
||||
instanceContext,
|
||||
instanceIdFromProps,
|
||||
);
|
||||
|
||||
let state: RecoilState<StateType> | RecoilValueReadOnly<StateType>;
|
||||
|
||||
if (componentStateV2.type === 'ComponentState') {
|
||||
state = componentStateV2.atomFamily({ instanceId });
|
||||
} else if (
|
||||
componentStateV2.type === 'ComponentSelector' ||
|
||||
componentStateV2.type === 'ComponentReadOnlySelector'
|
||||
) {
|
||||
state = componentStateV2.selectorFamily({ instanceId });
|
||||
} else {
|
||||
throw new Error('Invalid component state type');
|
||||
}
|
||||
|
||||
return useRecoilValue(state);
|
||||
};
|
||||
+5
-5
@@ -4,18 +4,18 @@
|
||||
// because a component state cannot change its type during its lifecycle
|
||||
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SerializableParam, SetterOrUpdater, useSetRecoilState } from 'recoil';
|
||||
|
||||
export const useSetRecoilComponentFamilyStateV2 = <
|
||||
export const useSetRecoilComponentFamilyState = <
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentState:
|
||||
| ComponentFamilyStateV2<StateType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<StateType, FamilyKey>,
|
||||
| ComponentFamilyState<StateType, FamilyKey>
|
||||
| ComponentFamilySelector<StateType, FamilyKey>,
|
||||
familyKey: FamilyKey,
|
||||
instanceIdFromProps?: string,
|
||||
): SetterOrUpdater<StateType> => {
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
|
||||
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SetterOrUpdater, useSetRecoilState } from 'recoil';
|
||||
|
||||
export const useSetRecoilComponentStateV2 = <ValueType>(
|
||||
componentState: ComponentStateV2<ValueType>,
|
||||
export const useSetRecoilComponentState = <ValueType>(
|
||||
componentState: ComponentState<ValueType>,
|
||||
instanceIdFromProps?: string,
|
||||
): SetterOrUpdater<ValueType> => {
|
||||
const componentInstanceContext = globalComponentInstanceContextMap.get(
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { ComponentFamilyStateKey } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilValueReadOnly, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyReadOnlySelector<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateType, 'ComponentFamilyReadOnlySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKey<FamilyKey>,
|
||||
) => RecoilValueReadOnly<StateType>;
|
||||
};
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import { ComponentFamilyStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilValueReadOnly, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyReadOnlySelectorV2<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentFamilyReadOnlySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKeyV2<FamilyKey>,
|
||||
) => RecoilValueReadOnly<StateType>;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { ComponentFamilyStateKey } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilState, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilySelector<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateType, 'ComponentFamilySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKey<FamilyKey>,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import { ComponentFamilyStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilState, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilySelectorV2<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentFamilySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKeyV2<FamilyKey>,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { ComponentFamilyStateKey } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilState, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyState<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateType, 'ComponentFamilyState'>;
|
||||
key: string;
|
||||
atomFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKey<FamilyKey>,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyStateKey<FamilyKey extends SerializableParam> =
|
||||
ComponentStateKey & {
|
||||
familyKey: FamilyKey;
|
||||
};
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyStateKeyV2<FamilyKey extends SerializableParam> =
|
||||
ComponentStateKeyV2 & {
|
||||
familyKey: FamilyKey;
|
||||
};
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import { ComponentFamilyStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilState, SerializableParam } from 'recoil';
|
||||
|
||||
export type ComponentFamilyStateV2<
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentFamilyState'>;
|
||||
key: string;
|
||||
atomFamily: (
|
||||
componentFamilyStateKey: ComponentFamilyStateKeyV2<FamilyKey>,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilValueReadOnly } from 'recoil';
|
||||
|
||||
export type ComponentReadOnlySelector<StateType> = {
|
||||
type: Extract<ComponentStateType, 'ComponentReadOnlySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentStateKey: ComponentStateKey,
|
||||
) => RecoilValueReadOnly<StateType>;
|
||||
};
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilValueReadOnly } from 'recoil';
|
||||
|
||||
export type ComponentReadOnlySelectorV2<StateType> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentReadOnlySelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentStateKey: ComponentStateKeyV2,
|
||||
) => RecoilValueReadOnly<StateType>;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilState } from 'recoil';
|
||||
|
||||
export type ComponentSelector<StateType> = {
|
||||
type: Extract<ComponentStateType, 'ComponentSelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentStateKey: ComponentStateKey,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilState } from 'recoil';
|
||||
|
||||
export type ComponentSelectorV2<StateType> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentSelector'>;
|
||||
key: string;
|
||||
selectorFamily: (
|
||||
componentStateKey: ComponentStateKeyV2,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { ComponentStateType } from '@/ui/utilities/state/component-state/types/ComponentStateType';
|
||||
import { RecoilState } from 'recoil';
|
||||
|
||||
export type ComponentState<StateType> = {
|
||||
type: Extract<ComponentStateType, 'ComponentState'>;
|
||||
key: string;
|
||||
atomFamily: (componentStateKey: ComponentStateKey) => RecoilState<StateType>;
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export type ComponentStateKey = {
|
||||
instanceId: string;
|
||||
};
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
export type ComponentStateKeyV2 = {
|
||||
instanceId: string;
|
||||
};
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export type ComponentStateTypeV2 =
|
||||
export type ComponentStateType =
|
||||
| 'ComponentState'
|
||||
| 'ComponentFamilyState'
|
||||
| 'ComponentSelector'
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentStateTypeV2 } from '@/ui/utilities/state/component-state/types/ComponentStateTypeV2';
|
||||
import { RecoilState } from 'recoil';
|
||||
|
||||
export type ComponentStateV2<StateType> = {
|
||||
type: Extract<ComponentStateTypeV2, 'ComponentState'>;
|
||||
key: string;
|
||||
atomFamily: (
|
||||
componentStateKey: ComponentStateKeyV2,
|
||||
) => RecoilState<StateType>;
|
||||
};
|
||||
+19
-19
@@ -1,36 +1,36 @@
|
||||
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
||||
import { selectorFamily, SerializableParam } from 'recoil';
|
||||
|
||||
import { ComponentFamilyReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelectorV2';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKeyV2';
|
||||
import { ComponentFamilyReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilyReadOnlySelector';
|
||||
import { ComponentFamilySelector } from '@/ui/utilities/state/component-state/types/ComponentFamilySelector';
|
||||
import { ComponentFamilyStateKey } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKey';
|
||||
import { ComponentInstanceStateContext } from '@/ui/utilities/state/component-state/types/ComponentInstanceStateContext';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SelectorGetter } from '@/ui/utilities/state/types/SelectorGetter';
|
||||
import { SelectorSetter } from '@/ui/utilities/state/types/SelectorSetter';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export function createComponentFamilySelectorV2<
|
||||
export function createComponentFamilySelector<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(options: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKey<FamilyKey>>;
|
||||
set?: never;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey>;
|
||||
}): ComponentFamilyReadOnlySelector<ValueType, FamilyKey>;
|
||||
|
||||
export function createComponentFamilySelectorV2<
|
||||
export function createComponentFamilySelector<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(options: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
set: SelectorSetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKey<FamilyKey>>;
|
||||
set: SelectorSetter<ValueType, ComponentFamilyStateKey<FamilyKey>>;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentFamilySelectorV2<ValueType, FamilyKey>;
|
||||
}): ComponentFamilySelector<ValueType, FamilyKey>;
|
||||
|
||||
export function createComponentFamilySelectorV2<
|
||||
export function createComponentFamilySelector<
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>({
|
||||
@@ -40,12 +40,12 @@ export function createComponentFamilySelectorV2<
|
||||
componentInstanceContext,
|
||||
}: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
set?: SelectorSetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKey<FamilyKey>>;
|
||||
set?: SelectorSetter<ValueType, ComponentFamilyStateKey<FamilyKey>>;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}):
|
||||
| ComponentFamilySelectorV2<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey> {
|
||||
| ComponentFamilySelector<ValueType, FamilyKey>
|
||||
| ComponentFamilyReadOnlySelector<ValueType, FamilyKey> {
|
||||
if (isDefined(componentInstanceContext)) {
|
||||
globalComponentInstanceContextMap.set(key, componentInstanceContext);
|
||||
}
|
||||
@@ -56,24 +56,24 @@ export function createComponentFamilySelectorV2<
|
||||
key,
|
||||
selectorFamily: selectorFamily<
|
||||
ValueType,
|
||||
ComponentFamilyStateKeyV2<FamilyKey>
|
||||
ComponentFamilyStateKey<FamilyKey>
|
||||
>({
|
||||
key,
|
||||
get,
|
||||
set,
|
||||
}),
|
||||
} satisfies ComponentFamilySelectorV2<ValueType, FamilyKey>;
|
||||
} satisfies ComponentFamilySelector<ValueType, FamilyKey>;
|
||||
} else {
|
||||
return {
|
||||
type: 'ComponentFamilyReadOnlySelector',
|
||||
key,
|
||||
selectorFamily: selectorFamily<
|
||||
ValueType,
|
||||
ComponentFamilyStateKeyV2<FamilyKey>
|
||||
ComponentFamilyStateKey<FamilyKey>
|
||||
>({
|
||||
key,
|
||||
get,
|
||||
}),
|
||||
} satisfies ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey>;
|
||||
} satisfies ComponentFamilyReadOnlySelector<ValueType, FamilyKey>;
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
import { ComponentFamilyStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKeyV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';
|
||||
import { ComponentFamilyStateKey } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateKey';
|
||||
import { ComponentInstanceStateContext } from '@/ui/utilities/state/component-state/types/ComponentInstanceStateContext';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import {
|
||||
@@ -20,7 +20,7 @@ type CreateComponentFamilyStateArgs<
|
||||
defaultValue:
|
||||
| ValueType
|
||||
| ((
|
||||
param: ComponentFamilyStateKeyV2<FamilyKey>,
|
||||
param: ComponentFamilyStateKey<FamilyKey>,
|
||||
) =>
|
||||
| ValueType
|
||||
| RecoilValue<ValueType>
|
||||
@@ -31,11 +31,11 @@ type CreateComponentFamilyStateArgs<
|
||||
effects?:
|
||||
| AtomEffect<ValueType>[]
|
||||
| ((
|
||||
param: ComponentFamilyStateKeyV2<FamilyKey>,
|
||||
param: ComponentFamilyStateKey<FamilyKey>,
|
||||
) => ReadonlyArray<AtomEffect<ValueType>>);
|
||||
};
|
||||
|
||||
export const createComponentFamilyStateV2 = <
|
||||
export const createComponentFamilyState = <
|
||||
ValueType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>({
|
||||
@@ -43,10 +43,10 @@ export const createComponentFamilyStateV2 = <
|
||||
effects,
|
||||
defaultValue,
|
||||
componentInstanceContext,
|
||||
}: CreateComponentFamilyStateArgs<
|
||||
}: CreateComponentFamilyStateArgs<ValueType, FamilyKey>): ComponentFamilyState<
|
||||
ValueType,
|
||||
FamilyKey
|
||||
>): ComponentFamilyStateV2<ValueType, FamilyKey> => {
|
||||
> => {
|
||||
if (isDefined(componentInstanceContext)) {
|
||||
globalComponentInstanceContextMap.set(key, componentInstanceContext);
|
||||
}
|
||||
@@ -54,10 +54,10 @@ export const createComponentFamilyStateV2 = <
|
||||
return {
|
||||
type: 'ComponentFamilyState',
|
||||
key,
|
||||
atomFamily: atomFamily<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>({
|
||||
atomFamily: atomFamily<ValueType, ComponentFamilyStateKey<FamilyKey>>({
|
||||
key,
|
||||
default: defaultValue,
|
||||
effects,
|
||||
}),
|
||||
} satisfies ComponentFamilyStateV2<ValueType, FamilyKey>;
|
||||
} satisfies ComponentFamilyState<ValueType, FamilyKey>;
|
||||
};
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
import { ComponentInstanceStateContext } from '@/ui/utilities/state/component-state/types/ComponentInstanceStateContext';
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const createComponentInstanceContext = <
|
||||
T extends ComponentStateKeyV2 = ComponentStateKeyV2,
|
||||
T extends ComponentStateKey = ComponentStateKey,
|
||||
>(
|
||||
initialValue?: T,
|
||||
) => {
|
||||
|
||||
+18
-18
@@ -2,39 +2,39 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import { ComponentInstanceStateContext } from '@/ui/utilities/state/component-state/types/ComponentInstanceStateContext';
|
||||
import { ComponentReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelectorV2';
|
||||
import { ComponentSelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentSelectorV2';
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentReadOnlySelector } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelector';
|
||||
import { ComponentSelector } from '@/ui/utilities/state/component-state/types/ComponentSelector';
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SelectorGetter } from '@/ui/utilities/state/types/SelectorGetter';
|
||||
import { SelectorSetter } from '@/ui/utilities/state/types/SelectorSetter';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export function createComponentSelectorV2<ValueType>(options: {
|
||||
export function createComponentSelector<ValueType>(options: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentStateKeyV2>;
|
||||
get: SelectorGetter<ValueType, ComponentStateKey>;
|
||||
set?: never;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentReadOnlySelectorV2<ValueType>;
|
||||
}): ComponentReadOnlySelector<ValueType>;
|
||||
|
||||
export function createComponentSelectorV2<ValueType>(options: {
|
||||
export function createComponentSelector<ValueType>(options: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentStateKeyV2>;
|
||||
set: SelectorSetter<ValueType, ComponentStateKeyV2>;
|
||||
get: SelectorGetter<ValueType, ComponentStateKey>;
|
||||
set: SelectorSetter<ValueType, ComponentStateKey>;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentSelectorV2<ValueType>;
|
||||
}): ComponentSelector<ValueType>;
|
||||
|
||||
export function createComponentSelectorV2<ValueType>({
|
||||
export function createComponentSelector<ValueType>({
|
||||
key,
|
||||
get,
|
||||
set,
|
||||
componentInstanceContext,
|
||||
}: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentStateKeyV2>;
|
||||
set?: SelectorSetter<ValueType, ComponentStateKeyV2>;
|
||||
get: SelectorGetter<ValueType, ComponentStateKey>;
|
||||
set?: SelectorSetter<ValueType, ComponentStateKey>;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentSelectorV2<ValueType> | ComponentReadOnlySelectorV2<ValueType> {
|
||||
}): ComponentSelector<ValueType> | ComponentReadOnlySelector<ValueType> {
|
||||
if (isDefined(componentInstanceContext)) {
|
||||
globalComponentInstanceContextMap.set(key, componentInstanceContext);
|
||||
}
|
||||
@@ -43,20 +43,20 @@ export function createComponentSelectorV2<ValueType>({
|
||||
return {
|
||||
type: 'ComponentSelector',
|
||||
key,
|
||||
selectorFamily: selectorFamily<ValueType, ComponentStateKeyV2>({
|
||||
selectorFamily: selectorFamily<ValueType, ComponentStateKey>({
|
||||
key,
|
||||
get,
|
||||
set,
|
||||
}),
|
||||
} satisfies ComponentSelectorV2<ValueType>;
|
||||
} satisfies ComponentSelector<ValueType>;
|
||||
} else {
|
||||
return {
|
||||
type: 'ComponentReadOnlySelector',
|
||||
key,
|
||||
selectorFamily: selectorFamily<ValueType, ComponentStateKeyV2>({
|
||||
selectorFamily: selectorFamily<ValueType, ComponentStateKey>({
|
||||
key,
|
||||
get,
|
||||
}),
|
||||
} satisfies ComponentReadOnlySelectorV2<ValueType>;
|
||||
} satisfies ComponentReadOnlySelector<ValueType>;
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
import { ComponentInstanceStateContext } from '@/ui/utilities/state/component-state/types/ComponentInstanceStateContext';
|
||||
import { ComponentStateKeyV2 } from '@/ui/utilities/state/component-state/types/ComponentStateKeyV2';
|
||||
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
|
||||
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
|
||||
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { AtomEffect, atomFamily } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
@@ -12,12 +12,12 @@ type CreateComponentInstanceStateArgs<ValueType> = {
|
||||
effects?: AtomEffect<ValueType>[];
|
||||
};
|
||||
|
||||
export const createComponentStateV2 = <ValueType>({
|
||||
export const createComponentState = <ValueType>({
|
||||
key,
|
||||
defaultValue,
|
||||
componentInstanceContext,
|
||||
effects,
|
||||
}: CreateComponentInstanceStateArgs<ValueType>): ComponentStateV2<ValueType> => {
|
||||
}: CreateComponentInstanceStateArgs<ValueType>): ComponentState<ValueType> => {
|
||||
if (isDefined(componentInstanceContext)) {
|
||||
globalComponentInstanceContextMap.set(key, componentInstanceContext);
|
||||
}
|
||||
@@ -25,10 +25,10 @@ export const createComponentStateV2 = <ValueType>({
|
||||
return {
|
||||
type: 'ComponentState',
|
||||
key,
|
||||
atomFamily: atomFamily<ValueType, ComponentStateKeyV2>({
|
||||
atomFamily: atomFamily<ValueType, ComponentStateKey>({
|
||||
key,
|
||||
default: defaultValue,
|
||||
effects: effects,
|
||||
}),
|
||||
} satisfies ComponentStateV2<ValueType>;
|
||||
} satisfies ComponentState<ValueType>;
|
||||
};
|
||||
Reference in New Issue
Block a user