Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Last active September 12, 2017 16:20
Show Gist options
  • Save mikebridge/c75835cda361c5967de301995894bf30 to your computer and use it in GitHub Desktop.
Save mikebridge/c75835cda361c5967de301995894bf30 to your computer and use it in GitHub Desktop.
A redux component template for intellij
//
// A TypeScript template for generating a Redux Component in IntelliJ.
//
// Create: Settings -> Editor => Live Templates -> Add.
// - give it an abbreviation (e.g. "redux") and a Description, and
// - set FILENAME_PASCAL to capitalize(fileNameWithoutExtension()) in "Edit Variables"
// - Make it available in JavaScript "JSX HTML", JavaScript "Statement" and TypeScript
//
// Usage: create a file, e.g. "myTemplate.tsx", then type "Ctrl-J", and the abbreviation, e.g. "redux".
//
import * as React from "react";
import * as ReactRedux from "react-redux";
interface I$FILENAME_PASCAL$State {}
// props exposed by this control
interface I$FILENAME_PASCAL$OwnProps {}
// props injected from the redux store
interface I$FILENAME_PASCAL$StoreProps {}
// action dispatchers injected from redux
interface I$FILENAME_PASCAL$DispatchProps {
actions: {
// loadItem: (itemid) => void;
};
}
type I$FILENAME_PASCAL$Props =
I$FILENAME_PASCAL$StoreProps &
I$FILENAME_PASCAL$OwnProps &
I$FILENAME_PASCAL$DispatchProps;
class $FILENAME_PASCAL$ extends React.Component<I$FILENAME_PASCAL$Props, I$FILENAME_PASCAL$State> {
constructor(props: I$FILENAME_PASCAL$Props) {
super(props);
// this.onClick = this.onClick.bind(this);
}
public render(): JSX.Element {
return(
<div>
Welcome to Redux
</div>
);
}
}
const mapStateToProps = (state: any, ownProps: I$FILENAME_PASCAL$OwnProps): I$FILENAME_PASCAL$StoreProps => ({
// item: state.item
});
const mapDispatchToProps = (dispatch, ownProps: I$FILENAME_PASCAL$OwnProps) : I$FILENAME_PASCAL$DispatchProps => ({
actions: {
// loadItem: (itemid) => dispatch(loadItem(itemid))
}
});
export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)($FILENAME_PASCAL$);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment