Skip to content

Commit

Permalink
rename useLegendStatePauseProvider to usePauseProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Oct 23, 2023
1 parent c271035 commit a25b5f7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 2.1.0
- Feat: useLegendStatePauseProvider to pause/resume all updates under a context
## 2.1.1
- Feat: usePauseProvider to pause/resume all updates under a context

## 2.0.3
- Feat: support persistence with no get
Expand Down
2 changes: 1 addition & 1 deletion react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './src/react/Computed';
export * from './src/react/For';
export { useLegendStatePauseProvider } from './src/react/useLegendStatePauseProvider';
export { usePauseProvider } from './src/react/usePauseProvider';
export * from './src/react/Memo';
export { Reactive, configureReactive } from './src/react/Reactive';
export type { IReactive } from './src/react/Reactive';
Expand Down
13 changes: 0 additions & 13 deletions src/react/useLegendStatePauseProvider.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions src/react/usePauseProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Observable, observable } from '@legendapp/state';
import { ReactNode, createContext, createElement, useState } from 'react';

export const PauseContext = createContext<Observable<boolean>>(null as any);

export function usePauseProvider() {
const [value] = useState(() => observable(false));
return {
PauseProvider: ({ children }: { children: ReactNode }) =>
createElement(PauseContext.Provider, { value }, children),
isPaused$: value,
};
}
4 changes: 2 additions & 2 deletions src/react/useSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@legendapp/state';
import React, { useContext, useRef } from 'react';
import { useSyncExternalStore } from 'use-sync-external-store/shim';
import { LegendStatePauseContext } from './useLegendStatePauseProvider';
import { PauseContext } from './usePauseProvider';
import { reactGlobals } from './react-globals';
import type { UseSelectorOptions } from './reactInterfaces';

Expand Down Expand Up @@ -119,7 +119,7 @@ export function useSelector<T>(selector: Selector<T>, options?: UseSelectorOptio

try {
const ref = useRef<SelectorFunctions<T>>();
const isPaused$ = useContext(LegendStatePauseContext);
const isPaused$ = useContext(PauseContext);
if (!ref.current) {
ref.current = createSelectorFunctions<T>(options, isPaused$);
}
Expand Down

0 comments on commit a25b5f7

Please sign in to comment.