Skip to content

Instantly share code, notes, and snippets.

@steida
Created March 4, 2014 00:12
Show Gist options
  • Save steida/9337512 to your computer and use it in GitHub Desktop.
Save steida/9337512 to your computer and use it in GitHub Desktop.
React.js with dependency injection based on types. Snippet from Este.js (not released yet).
/** @jsx React.DOM */
goog.provide('app.drugs.react.DrugAutoComplete');
goog.require('este.thirdParty.react');
goog.require('goog.ui.ac.AutoComplete');
/**
* @param {app.Routes} routes
* @constructor
*/
app.drugs.react.DrugAutoComplete = function(routes) {
this.reactClass = React.createClass(/** @lends {React.ReactComponent.prototype} */{
render: function() {
return (
<div className="drug-autocomplete">
<input
className="form-control"
placeholder={this.props.placeholder}
onFocus={this.onInputFocus}
ref="input"
/>
<button className="search" onFocus={this.onButtonFocus} tabIndex="-1">
search drug
</button>
</div>
);
},
// Some Closure Library handler using injected app.Routes instance.
onAutoCompleteUpdate: function(e) {
this.refs['input'].getDOMNode().value = ''
var drugUrlName = e.row;
routes.redirectToDrugsDetail(drugUrlName);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment