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

https://github.com/irskep/baconreactmixin

React mixin to set component state from Bacon.js observables
https://github.com/irskep/baconreactmixin

Last synced: 3 months ago
JSON representation

React mixin to set component state from Bacon.js observables

Awesome Lists containing this project

README

          

# BaconReactMixin

`BaconReactMixin` sets component state from [Bacon.js](1) observables. It
depends on [React.js](2), [underscore.js](3), and Bacon.js.

[1]: https://github.com/baconjs/bacon.js
[2]: https://facebook.github.io/react/
[3]: http://underscorejs.org/

## Installation

`BaconReactMixin` can be installed as an npm package or with a `` tag.

```sh
# actually this doesn't work yet because we haven't published it.
# but you can download the tarball and use it this way.
npm install BaconReactMixin
```

```html
<script src="BaconReactMixin.js">
```

## Usage

`BaconReactMixin({key: property})` returns a mixin that sets `state[key]`
on the component whenever `property` is updated.

Properties must have initial values. If you want to use a property without
an initial value, you can just use `property.startWith(undefined)`.

Constants are also valid.

Streams may work sometimes but will not be reliable. Use `toProperty()` to
avoid problems.

## Small example

```jsx
var BaconyComponent = React.createClass({
mixins: [BaconReactMixin({
a: Bacon.constant('a'),
b: 'b'
})],
render: function() {
return


{this.state.a},
{this.state.b}

}
});
```

## Complete example

```html

BaconReactMixin demo









// update the date every second
var date = Bacon.fromPoll(
1000, function() { return new Date(); }).toProperty(new Date());

// simple component that renders date's value
var DateView = React.createClass({
mixins: [BaconReactMixin({date: date})],
render: function() {
return React.DOM.div(null, "Date: " + this.state.date);
}
})

// put the component in the page
React.renderComponent(DateView(), document.getElementById("content"));

```