Skip to content

Commit

Permalink
Merge 2e5d6c7 into 818f783
Browse files Browse the repository at this point in the history
  • Loading branch information
zgsrc committed Feb 28, 2018
2 parents 818f783 + 2e5d6c7 commit 3be19e6
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 62 deletions.
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ obj.a = 2
console.log(obj.sum) // -> 4
```

#### Reactive Classes

Ground up support for reactive class models using mixins

```javascript
class SomeClass extends Computable(Observable(Object)) {
constructor(data, opts) {
super(data, opts)

this.value = 10 // writes to observed object automagically
}
}
```

#### React store

Hyperactiv contains built-in helpers to easily create a reactive store which re-renders your React components.
Expand Down Expand Up @@ -424,7 +438,8 @@ const handler = function(keys, value) {
}

// The deep flag ensures that the handler will be triggered when the mutation happens in a nested array/object
const observer = observe(object, { handler, deep: true })
const observer = observe(object, { bubble: true, deep: true })
observer.__handler = handler
object.a.b[0].c = 'value'

// The handler is triggered after each mutation
Expand All @@ -447,7 +462,7 @@ observe(Object | Array, {
batch: boolean,
deep: boolean,
bind: boolean,
handler: function
bubble: boolean
}) => Proxy
```

Expand All @@ -471,11 +486,9 @@ Observe nested objects and when setting new properties.

- `bind: boolean`

Automatically bind methods to the observed object.
- `handler: Function(ancestry: String[], value: Object, originalObject: Object)`
Bubble mutations up the object hierarchy, triggering handlers along the way.

Callback performed whenever the observed object is mutated.
- `bubble: boolean`

### computed

Expand Down Expand Up @@ -509,9 +522,14 @@ dispose(Function) => void

### handlers

Helper handlers used to perform various tasks whenever an observed object is mutated.
You can "wire tap" any observed object by assigning a callback to the `__handler` property. When `bubble` is set along with `deep`, the `__handler` will receive mutations from nested objects.

```javascript
const observer = observe(object, { bubble: true, deep: true })
observer.__handler = (keys, value, oldValue, observedObject) => { }
```

Note that handlers are written separately from the main hyperactiv codebase and need to be imported from a separate path.
Helper handlers can be used to perform various tasks whenever an observed object is mutated.

```js
import handlers from 'hyperactiv/handlers'
Expand All @@ -526,6 +544,8 @@ Or alternatively if you prefer script tags :
const... } = window['hyperactiv-handlers']
```

__Note__: Handlers are written separately from the main hyperactiv codebase and need to be imported from a separate path.

#### write

Will generate a handler to transpose writes onto another object.
Expand Down
4 changes: 2 additions & 2 deletions dist/hyperactiv.map.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyperactiv",
"version": "0.2.2",
"version": "0.3.0",
"description": "Super small observable & reactive objects library.",
"main": "dist/index.js",
"repository": "https://github.com/elbywan/hyperactiv",
Expand Down
2 changes: 1 addition & 1 deletion react/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3be19e6

Please sign in to comment.