Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-observable-mixin

Package Overview
Dependencies
Maintainers
3
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.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by1200%
Maintainers
3
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

FAQs

Package last updated on 23 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc