Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Aug 31, 2018
1 parent 7191ccf commit db2000c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ In other terms whenever a property from an observed object is **mutated**, every

Of course, Hyperactiv **automatically** handles these dependencies so you **never** have to explicitly declare anything. ✨

----

#### Minimal working example

```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'.
// This function depends on properties 'a' and 'b'.
computed(() => {
consta, b } = observed
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.

// Whenever properties 'a' or 'b' are mutated…
observed.a = 2
// The function will be automagically be called.
// <- a + b = 4
observed.b = 3
// <- a + b = 5
observed.c = 1
// No function depend on 'c', so nothing will happen.
```

## Demo
Expand Down Expand Up @@ -604,4 +610,4 @@ let copy = {}, copy2 = {}, obj = observe({ observed: 'object' }, {
write(copy2)
])
})
```
```

0 comments on commit db2000c

Please sign in to comment.