You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-observable-mixin

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-observable-mixin

Container like observable mixin for ReactJS.

1.0.2
Source
npmnpm
Version published
Weekly downloads
5
-54.55%
Maintainers
1
Weekly downloads
 
Created
Source

react-observable-mixin

Build Status Coverage Status Dependency Status devDependency Status

Container like observable mixin for ReactJS.

Install

npm install react-observable-mixin

Usage

import React from 'react';
import {ObservablePropTypes, RxObservableMixin} from 'react-observable-mixin';

export default React.createClass({
  mixins: [RxObservableMixin],

  propTypes: {
    name$: ObservablePropTypes.observable,
    lastName$: ObservablePropTypes.observable
  },

  render() {
    return <span>{this.state.name || ''} {this.state.lastName || ''}</span>;
  }
});

Mixins

RxObservableMixin

This mixin automatically subscribes to props that are observables ($ at the end and a method subscribe). When the observable emits a new value, the value is automatically injected in the state.

mixins: [RxObservableMixin]
componentWillReceiveStateFromObservables(state)

You can implement this method and it will be called when a value is received from observable and that the state will be updated.

componentWillReceiveStateFromObservables(nextState) {
  console.log(nextState.name); // new value
  console.log(this.state.name); // previous value
}
componentWillReceiveErrorFromObservables(error)

You can implement this method and it will be called when an error is emitted from an observable.

componentWillReceiveErrorFromObservables(error) {
  throw error; // Throw error emitted from an observable
}

PropTypes

ObservablePropTypes.observable

A validator for Rx.Observable instance.

propTypes() {
  return {
    name$: ObservablePropTypes.observable
  };
}

License

MIT

Keywords

react

FAQs

Package last updated on 21 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts