Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/acryps/page-observable

Renderable observables for @acryps/page
https://github.com/acryps/page-observable

Last synced: 5 days ago
JSON representation

Renderable observables for @acryps/page

Awesome Lists containing this project

README

        

[![npm version](https://badge.acryps.com/npm/@acryps%2Fpage-observable)](http://badge.acryps.com/go/npm/@acryps%2Fpage-observable)
# @acryps/page observables
Adds observables to page!

Creating an observable
```
const magicNumber = new Observable();
```

Listening for changes
```
magicNumber.subscribe(value => console.log(value));
```

Pushing new changes
```
magicNumber.emit(1);
```

Embedding value into component
```
class ItemsComponent extends Component {
render() {
return
Mapped to a string: {magicNumber.map(value => value.toFixed(3))}

Mapped to an element: {magicNumber.map(value =>
{value}
)}

Automatically mapped: {magicNumber} (only recommended for strings & numbers)
;
}
}
```

## Example
```

class PageComponent {
render(child) {
return

Shop


Cart ({CartComponent.items.map(items => items.length)})

{child}
;
}
}

class CartComponent {
static items = new Observable();

items = [
'carrots',
'apples'
];

render() {
return
{
items.push('bananas');

CartComponent.items.emit(items);
}}>
;
}
}
```