Skip to content

Commit

Permalink
Reworded some readme parts
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Aug 30, 2018
1 parent bde3fa6 commit 7191ccf
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,30 @@

Hyperactiv is a super small (< 1kb minzipped) library which **observes** object mutations and **computes** functions depending on those changes.

In other terms, whenever an *observed object property* is **mutated**, the *computed functions* that **depend** on this property will be **called**.
In other terms whenever a property from an observed object is **mutated**, every function that **depend** on this property are **called** right away.

Of course, Hyperactiv **automatically** handles these dependencies so you **never** have to explicitly declare which *computed function* depends on which *observed property*.
Of course, Hyperactiv **automatically** handles these dependencies so you **never** have to explicitly declare anything. ✨

```js
importobserve, compute } from "hyperactiv"

// This object is observed.
const observed = observe({ a: 1, b: 2, c: 0 })

// This function depend on properties 'a' and 'b'.
computed(() => {
console.log(`<- a + b = ${a + b}`)
})
// <- a + b = 3

// Whenever properties 'a' or 'b' are mutated (but not c), the function will be automatically be called.

observed.a = 2
// <- a + b = 4
observed.b = 3
// <- a + b = 5
observed.c = 1
```

## Demo

Expand Down Expand Up @@ -61,7 +82,7 @@ const { computed, observe, dispose } = hyperactiv

## Usage

#### Observe object and arrays
#### 1. Observe object and arrays

```js
const observedObject = observe({ a: 5, b: 4 })
Expand All @@ -72,7 +93,7 @@ const observedObject = observe({ a: 5, b: 4 })
const observedArray = observe([ 3, 2, 1 ], { deep: true })
```

#### Define computed functions
#### 2. Define computed functions

```js
let result = 0
Expand All @@ -93,7 +114,7 @@ console.log(result) // -> 15
const _ = computed(() => {}, { autoRun: false })
```

#### Mutate observed properties
#### 3. Mutate observed properties

```js
// computedFunction will be called each time one of its dependencies is changed.
Expand All @@ -111,7 +132,7 @@ observedArray.pop()
console.log(result) // -> 17
```

#### Release computed functions
#### 4. Release computed functions

```js
// Observed objects store computed function references in a Set, so you need to
Expand Down

0 comments on commit 7191ccf

Please sign in to comment.