From a25b5f79fe6ba1e62b8497321537d803912909b3 Mon Sep 17 00:00:00 2001 From: Jay Meistrich Date: Mon, 23 Oct 2023 15:55:22 +0100 Subject: [PATCH] rename useLegendStatePauseProvider to usePauseProvider --- CHANGELOG.md | 4 ++-- react.ts | 2 +- src/react/useLegendStatePauseProvider.tsx | 13 ------------- src/react/usePauseProvider.tsx | 13 +++++++++++++ src/react/useSelector.ts | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 src/react/useLegendStatePauseProvider.tsx create mode 100644 src/react/usePauseProvider.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 66df23f21..644704b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/react.ts b/react.ts index 5cb002f37..f31da1ced 100644 --- a/react.ts +++ b/react.ts @@ -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'; diff --git a/src/react/useLegendStatePauseProvider.tsx b/src/react/useLegendStatePauseProvider.tsx deleted file mode 100644 index 4d49a411f..000000000 --- a/src/react/useLegendStatePauseProvider.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable, observable } from '@legendapp/state'; -import { ReactNode, createContext, createElement, useState } from 'react'; - -export const LegendStatePauseContext = createContext>(null as any); - -export function useLegendStatePauseProvider() { - const [value] = useState(() => observable(false)); - return { - LegendStatePauseProvider: ({ children }: { children: ReactNode }) => - createElement(LegendStatePauseContext.Provider, { value }, children), - isPaused$: value, - }; -} diff --git a/src/react/usePauseProvider.tsx b/src/react/usePauseProvider.tsx new file mode 100644 index 000000000..e9cc9e795 --- /dev/null +++ b/src/react/usePauseProvider.tsx @@ -0,0 +1,13 @@ +import { Observable, observable } from '@legendapp/state'; +import { ReactNode, createContext, createElement, useState } from 'react'; + +export const PauseContext = createContext>(null as any); + +export function usePauseProvider() { + const [value] = useState(() => observable(false)); + return { + PauseProvider: ({ children }: { children: ReactNode }) => + createElement(PauseContext.Provider, { value }, children), + isPaused$: value, + }; +} diff --git a/src/react/useSelector.ts b/src/react/useSelector.ts index fc4f71693..d61a9e4a3 100644 --- a/src/react/useSelector.ts +++ b/src/react/useSelector.ts @@ -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'; @@ -119,7 +119,7 @@ export function useSelector(selector: Selector, options?: UseSelectorOptio try { const ref = useRef>(); - const isPaused$ = useContext(LegendStatePauseContext); + const isPaused$ = useContext(PauseContext); if (!ref.current) { ref.current = createSelectorFunctions(options, isPaused$); }