Skip to content

Commit

Permalink
feat: removed add, remove, find APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ncphillips committed Mar 5, 2020
1 parent 4c2c4f4 commit 064e830
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 48 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ user.age = 26 // Happy Birthday Bill, you're 26 years old!
import { watchCollection } from 'babas'

const bob = {
id: 'bob',
name: 'Bob',
age: 25,
}
Expand All @@ -71,17 +70,15 @@ const unsubscribe = users.subscribe(() => {
There are 3 ways to add entries:

```js
user.add({ id: 'bill', name: 'Bill', age: 30 })
user.janet = { id: 'janet', name: 'Janet', age: 23 }
user['polly'] = { id: 'polly', name: 'Polly', age: 54 }
user.janet = { name: 'Janet', age: 23 }
user['polly'] = { name: 'Polly', age: 54 }
```

**Removing Entries**

There are 3 ways to remove entries:
There are 2 ways to remove entries:

```js
users.remove(bob)
delete users.polly
delete users['bill']
```
Expand Down
9 changes: 0 additions & 9 deletions src/watch-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ export function watchCollection<T>(
const index = subscribers.findIndex(({ cb }) => cb === removeCB)
subscribers.splice(index, 1)
},
add(id: string, item: T) {
return (watchableCollection[id] = item)
},
remove(id: string) {
delete watchableCollection[id]
},
find(id: string) {
return watchableCollection[id]
},
notifyChange() {
subscribers.forEach(({ cb }) => {
cb()
Expand Down
33 changes: 0 additions & 33 deletions test/watch-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ describe('watch-colletion', () => {
users = watchCollection<User>()
})

describe('using collection.add(entry)', () => {
it('calls subscriber', () => {
users.subscribe(cb)

users.add('bob', bob)

expect(cb).toHaveBeenCalled()
})

it('adds the entry to the collection', () => {
users.add('bob', bob)

expect(users.bob).toBe(bob)
expect(users['bob']).toBe(bob)
})
})

describe('using collection[id] = entry', () => {
it('calls subscriber', () => {
users.subscribe(cb)
Expand Down Expand Up @@ -78,22 +61,6 @@ describe('watch-colletion', () => {
users = watchCollection<User>({ bob })
})

describe('using collection.remove(id)', () => {
it('calls subscriber', () => {
users.subscribe(cb)

users.remove('bob')

expect(cb).toHaveBeenCalled()
})
it('removes the entry', () => {
users.remove('bob')

expect(users.bob).toBeUndefined()
expect(users['bob']).toBeUndefined()
})
})

describe('useing delete collection[id]', () => {
it('calls subscriber', () => {
users.subscribe(cb)
Expand Down

0 comments on commit 064e830

Please sign in to comment.