Skip to content

Commit c8b9652

Browse files
committed
Type fixing
1 parent 4136c32 commit c8b9652

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-context-mutex",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Use a mutex lock to prevent callback duplication, now used as a React hook",
55
"main": "dist/react-context-mutex.js",
66
"module": "dist/react-context-mutex.es.js",

src/MutexContext/__tests__/useMutex.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const timeout = (ms: number) => {
1414
};
1515

1616
const useMockFetch = (props: MockMutexProps) => {
17-
const Mutex = useMutex();
18-
const mutex = new Mutex(props.mutexKey);
17+
const MutexRunner = useMutex();
18+
const mutex = new MutexRunner(props.mutexKey);
1919

2020
useEffect(() => {
2121
const executeFetch = async () => {

src/MutexContext/createMutex.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export interface Mutex {
1+
export type MutexRunner = new (id: string) => {
2+
id: string;
23
/** Runs the mutex callback in case it's not locked */
34
run: (callback: () => void) => void;
45
/** Locks the mutex instance */
@@ -7,10 +8,10 @@ export interface Mutex {
78
unlock: () => void;
89
/** Shows whether the mutex instance is locked or not */
910
isLocked: () => boolean;
10-
}
11+
};
1112

12-
export const createMutex = (context: string[]) => {
13-
return class MutexRunner implements Mutex {
13+
export const createMutex = (context: string[]): MutexRunner => {
14+
return class Mutex {
1415
public id: string;
1516

1617
constructor(id: string) {

src/MutexContext/useMutex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createMutex } from './createMutex';
44

55
export const useMutex = () => {
66
const mutexContext = useContext(MutexContext);
7-
const Mutex = createMutex(mutexContext);
7+
const MutexRunner = createMutex(mutexContext);
88

9-
return Mutex;
9+
return MutexRunner;
1010
};

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Mutex as MutexInterface } from './MutexContext/createMutex';
1+
import { MutexRunner as MutexRunnerType } from './MutexContext/createMutex';
22

33
export { useMutex } from './MutexContext/useMutex';
4-
export type Mutex = MutexInterface;
4+
export type MutexRunner = MutexRunnerType;

0 commit comments

Comments
 (0)