Skip to content

Commit

Permalink
Review Nora
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Mar 25, 2024
1 parent 8c3e0fc commit 35fbec8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useTreeViewJSXNodes: TreeViewPlugin<UseTreeViewJSXNodesSignature> =
instance,
setState,
}) => {
instance.preventItemUpdate();
instance.preventItemUpdates();

const insertJSXNode = useEventCallback((node: TreeViewNode) => {
setState((prevState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useTreeViewKeyboardNavigation: TreeViewPlugin<
);

React.useEffect(() => {
if (instance.isItemUpdatePrevented()) {
if (instance.areItemUpdatesPrevented()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ export const useTreeViewNodes: TreeViewPlugin<UseTreeViewNodesSignature> = ({
return childrenIds;
};

const isItemUpdatedPreventedRef = React.useRef(false);
const preventItemUpdate = React.useCallback(() => {
isItemUpdatedPreventedRef.current = true;
const areItemUpdatesPreventedRef = React.useRef(false);
const preventItemUpdates = React.useCallback(() => {
areItemUpdatesPreventedRef.current = true;
}, []);

const isItemUpdatePrevented = React.useCallback(() => isItemUpdatedPreventedRef.current, []);
const areItemUpdatesPrevented = React.useCallback(() => areItemUpdatesPreventedRef.current, []);

React.useEffect(() => {
if (instance.isItemUpdatePrevented()) {
if (instance.areItemUpdatesPrevented()) {
return;
}

Expand Down Expand Up @@ -216,8 +216,8 @@ export const useTreeViewNodes: TreeViewPlugin<UseTreeViewNodesSignature> = ({
getChildrenIds,
getNavigableChildrenIds,
isNodeDisabled,
preventItemUpdate,
isItemUpdatePrevented,
preventItemUpdates,
areItemUpdatesPrevented,
});

populatePublicAPI<UseTreeViewNodesSignature>(publicAPI, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export interface UseTreeViewNodesInstance<R extends {}> {
* Freeze any future update to the state based on the `items` prop.
* This is useful when `useTreeViewJSXNodes` is used to avoid having conflicting sources of truth.
*/
preventItemUpdate: () => void;
preventItemUpdates: () => void;
/**
* Check if the updates to the state based on the `items` prop are prevented.
* This is useful when `useTreeViewJSXNodes` is used to avoid having conflicting sources of truth.
* @returns {boolean} `true` if the updates to the state based on the `items` prop are prevented.
*/
isItemUpdatePrevented: () => boolean;
areItemUpdatesPrevented: () => boolean;
}

export interface UseTreeViewNodesPublicAPI<R extends {}>
Expand Down

0 comments on commit 35fbec8

Please sign in to comment.