Skip to content

Commit

Permalink
docs: readme badges
Browse files Browse the repository at this point in the history
  • Loading branch information
ncphillips committed Mar 5, 2020
1 parent 000d1ba commit 4c2c4f4
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)

# babas

A tiny library for watching objects.
Expand All @@ -11,13 +13,13 @@ A tiny library for watching objects.
By default all values are watched:

```js
import { watch } from 'babas';
import { watch } from 'babas'

const user = watch({ name: 'Bob', age: 25 });
const user = watch({ name: 'Bob', age: 25 })

user.subscribe(user => {
console.log('User updated');
});
console.log('User updated')
})
```

**Watching Specific Values**
Expand All @@ -26,62 +28,62 @@ A `subscription` object can be passed as the second argument to restrict
which properties should be watched.

```js
import { watch } from 'babas';
import { watch } from 'babas'

const user = watch({ name: 'Bob', age: 25 });
const user = watch({ name: 'Bob', age: 25 })

user.subscribe(
user => {
console.log(`Happy Birthday ${user.name}, you're ${user.age} years old!`);
console.log(`Happy Birthday ${user.name}, you're ${user.age} years old!`)
},
{ age: true }
);
)

user.name = 'Bill';
user.name = 'Bill'

user.age = 26; // Happy Birthday Bill, you're 26 years old!
user.age = 26 // Happy Birthday Bill, you're 26 years old!
```

### `watchCollection`

```js
import { watchCollection } from 'babas';
import { watchCollection } from 'babas'

const bob = {
id: 'bob',
name: 'Bob',
age: 25,
};
}

const users = watchCollection({ bob });
const users = watchCollection({ bob })
```

**Subscribing**

```js
const unsubscribe = users.subscribe(() => {
console.log(`The guest list has changed.`);
});
console.log(`The guest list has changed.`)
})
```

**Adding Entries**

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.add({ id: 'bill', name: 'Bill', age: 30 })
user.janet = { id: 'janet', name: 'Janet', age: 23 }
user['polly'] = { id: 'polly', name: 'Polly', age: 54 }
```

**Removing Entries**

There are 3 ways to remove entries:

```js
users.remove(bob);
delete users.polly;
delete users['bill'];
users.remove(bob)
delete users.polly
delete users['bill']
```

## Local Development
Expand Down

0 comments on commit 4c2c4f4

Please sign in to comment.