GithubHelp home page GithubHelp logo

react-observer's Introduction

react-observer

Respond to most events in React components.

build status coverage license version downloads

Make React actually reactive.

This one is fairly specific to most right now - ideally it should support the ES7 observable interface, but this works. See the discussion here.

TODO

  • Tests
  • Runnable examples
  • Incorporate invariant

Usage

Use it on DOM elements.

import observer from 'react-observer';
import { fromEvent, map } from 'most';


@observer
class MyComponent extends Component {

	observe(props) {
		return {
			mouse: map((ev) => {
				return { x: ev.clientX, y: ev.clientY };
			}, fromEvent('mousedown', document))
		};
	}

	render() {
		<div>Position: ({this.mouse.x},{this.mouse.y})</div>
	}
}

Use it with afflux.

import observer from 'react-observer';
import { fromEvent, map } from 'most';


@observer
class MyComponent extends Component {

	observe(props) {
		return {
			user: this.stores.users.current
		};
	}

	render() {
		<div>User: {this.user.name}</div>
	}
}

Use it to make simple timers.

import observer from 'react-observer';
import { create } from 'most';


@observer
class MyComponent extends Component {

	observe(props) {
		return {
			time: create(add => {
				const interval = setInterval(() => {
					add(new Date());
				}, 1000);
				return () => { clearInterval(interval); };
			})
		};
	}

	render() {
		<div>It is now: {this.time}</div>
	}
}

react-observer's People

Contributors

izaakschroeder avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.