Skip to content

Instantly share code, notes, and snippets.

@jgable
Created May 6, 2015 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgable/0d1e07dc5a5c114c442e to your computer and use it in GitHub Desktop.
Save jgable/0d1e07dc5a5c114c442e to your computer and use it in GitHub Desktop.
Thoughts on React VisualStateManager

React VisualStateManager

A declarative visual state transition manager.

Wishlist

var { VisualStateComponent, VisualState, ColorAnimation } = require('vsm');

class StopLight extends VisualStateComponent {
  componentDidMount() {
    this.interval = setInterval(this.cycleLights, 20000);
  }
  
  componentWillUnMount() {
	clearInterval(this.interval);  
  }
  
  render() {
	return (
	  <div className="stoplight">
	  	<div className="light top"></div>
		<div className="light mid"></div>
		<div className="light bot"></div>
	  </div>
	);
  }
  
  getVisualState() {
	return (
	  <VisualState name="stop">
	    <ColorAnimation target=".top" from="transparent" to="red" duration="0.300" />
	  </VisualState>
	  <VisualState name="caution">
	    <ColorAnimation target=".mid" from="transparent" to="yellow" duration="0.300" />
	  </VisualState>
	  <VisualState name="go">
	    <ColorAnimation target=".bot" from="transparent" to="green" duration="0.300" />
	  </VisualState>
	);
  },
  
  cycleLights() {
	this.goToVisualState('stop');
	setTimeout(function () {
	  this.goToVisualState('go');
	  
	  setTimeout(function () {
		this.goToVisualState('caution');
		
		setTimeout(function () {
		  this.goToVisualState('stop');
		}.bind(this), 3000);
	  }.bind(this), 5000);
	}.bind(this), 2000);  
  }
}
@jgable
Copy link
Author

jgable commented May 19, 2015

This has started to come together as react-vsm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment