Skip to content

Commit

Permalink
rename pop ro remove
Browse files Browse the repository at this point in the history
  • Loading branch information
droganov committed Sep 22, 2019
1 parent a8b41f5 commit 15e9bd2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/useQueue.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `useQueue`

React state hook implements simple queue.
React state hook implements simple FIFO queue.


## Usage
Expand All @@ -9,7 +9,7 @@ React state hook implements simple queue.
import { useQueue } from 'react-use';

const Demo = () => {
const { add, pop, first, last, size } = useQueue();
const { add, remove, first, last, size } = useQueue();

return (
<div>
Expand All @@ -19,7 +19,7 @@ const Demo = () => {
<li>size: {size}</li>
</ul>
<button onClick={() => add((last || 0) + 1)}>Add</button>
<button onClick={() => pop()}>Pop</button>
<button onClick={() => pop()}>Remove</button>
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/__stories__/useQueue.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useQueue } from '..';
import ShowDocs from './util/ShowDocs';

const Demo = () => {
const { add, pop, first, last, size } = useQueue();
const { add, remove, first, last, size } = useQueue();
return (
<div>
<ul>
Expand All @@ -13,7 +13,7 @@ const Demo = () => {
<li>size: {size}</li>
</ul>
<button onClick={() => add((last || 0) + 1)}>Add</button>
<button onClick={() => pop()}>Pop</button>
<button onClick={() => remove()}>Removw</button>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/useQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it('appends new member', () => {
it('pops oldest member', () => {
const { result } = setUp([1, 2]);
act(() => {
result.current.pop();
result.current.remove();
});
const { first, size } = result.current;
expect(first).toEqual(2);
Expand Down
4 changes: 2 additions & 2 deletions src/useQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';

export interface QueueMethods<T> {
add: (item: T) => void;
pop: () => T;
remove: () => T;
first: T;
last: T;
size: number;
Expand All @@ -14,7 +14,7 @@ const useQueue = <T>(initialValue: T[] = []): QueueMethods<T> => {
add: value => {
set(queue => [...queue, value]);
},
pop: () => {
remove: () => {
let result;
set(([first, ...rest]) => {
result = first;
Expand Down

0 comments on commit 15e9bd2

Please sign in to comment.