Skip to content

Instantly share code, notes, and snippets.

@dvtng
dvtng / jquery.prebind.js
Created June 27, 2011 23:51 — forked from jonathanconway/jquery.prebind.js
preBind() - Add an event binding *before* any pre-existing bindings. (An early version, may not work in all scenarios)
$.fn.preBind = function(type, data, fn) {
this.bind(type, data, fn);
var currentBindings = this.data('events')[type];
this.data('events')[type] = currentBindings.slice(-1)
.concat(currentBindings.slice(0, -1));
return this;
};
class Panel extends React.Component {
renderHeading() {
// ...
}
renderBody() {
// ...
}
render() {
const PanelHeader = (props) => (
// ...
);
const PanelBody = (props) => (
// ...
);
class Panel extends React.Component {
render() {
class CommentTemplate extends React.Component {
static propTypes = {
// Declare slots as type node
metadata: PropTypes.node,
actions: PropTypes.node,
};
render() {
return (
<div>
class Comment extends React.Component {
render() {
const metadata = this.props.publishTime ?
<PublishTime time={this.props.publishTime} /> :
<span>Saving...</span>;
const actions = [];
if (this.props.isSignedIn) {
actions.push(<LikeAction />);
actions.push(<ReplyAction />);
class Document extends React.Component {
componentDidMount() {
ReactDOM.findDOMNode(this).addEventListener('click', this.onClick);
}
componentWillUnmount() {
ReactDOM.findDOMNode(this).removeEventListener('click', this.onClick);
}
onClick = (e) => {
function withLinkAnalytics(mapPropsToData, WrappedComponent) {
class LinkAnalyticsWrapper extends React.Component {
componentDidMount() {
ReactDOM.findDOMNode(this).addEventListener('click', this.onClick);
}
componentWillUnmount() {
ReactDOM.findDOMNode(this).removeEventListener('click', this.onClick);
}
class Document extends React.Component {
render() {
// ...
}
}
export default withLinkAnalytics((props) => ({
documentId: props.documentId
}), Document);
<CommentTemplate metadata={metadata} actions={actions}>
{text}
</CommentTemplate>
// router concepts
// - route declaration (abstract) vs. route implementation (concrete)
// - transitionIds
// - onPrepare, onTransitionStart, onTransitionEnd
// - global click handler
// - useRouterState, useRouterActions
type RouteInfo = {
name: string;
params: { [key]: string };