1.0.3 • Published 7 years ago

smallorange-reactive-store-react v1.0.3

Weekly downloads
6
License
ISC
Repository
github
Last release
7 years ago

CircleCI

React Component for Small Orange Reactive Store

It attaches observables helpers to react components, and automatically tearsdown when destroyed;

Methods

	on(...filter: string, replay: boolean = false): Observable<any>;
	once(...filter: string, replay: boolean = false): Observable<any>;
	trigger(key: string, data: any = null): void;

Usage

	import React from 'react';
	import {
		Component
	} from 'smallorange-reactive-store-react';

	export class Messages extends Component {
		constructor(props) {
			super(props);

			this.state = {
				data: []
			};
		}

		componentDidMount() {
			this.on('inputChange')
				.subscribe(doSomething);

			this.once('destroy')
				.subscribe(() => console.log('Bye!'));
		}

		render() {
			return (
				<input type="text" onChange={e => this.trigger('inputChange', e)}>
			);
		}
	}