Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
import {connect} from 'react-redux';
import View from './Scientist.jsx';
export default connect((state, props)=>{
return {
...state.scientists.get(props.scientist),
};
})(View);
export default function Scientist({dob, fullname, imageSrc}) {
return (
<div>
<h3>{fullname}</h3>
<h5>{dob}</h5>
<img src={imageSrc} />
</div>
)
}
import {connect} from 'react-redux';
import {compose, withPropsOnChange} from 'recompose';
import View from './Scientist.jsx';
export default compose(
connect((state, props)=>{
return {
...state.scientists.get(props.scientist),
};
}),
@import "lucid-mixins";
// .lucid-tab('.html', rgb(60, 120, 168));
// .lucid-tab('.js', rgb(220,20,60));
// .lucid-tab('.json', rgb(252,128,27));
// .lucid-tab('.coffee', rgb(214,233,245));
// .lucid-tab('.py', rgb(60, 120, 168));
// .lucid-tab('.less', rgb(50, 90, 162));
.lucid-tab('.scss', rgb(144,198,149));
// .lucid-tab('.css', #29abde);
.lucid-tab(@ext: ''; @color: '') {
tabs-bar tabs-tab .title[data-name*="@{ext}"],
.tab-bar .tab .title[data-name*="@{ext}"] {
border-top: 2px solid @color;
// color: @color;
}
}
@hartzis
hartzis / Image.jsx
Last active October 4, 2018 06:57
React Universal/Isomorphic Image onError Component
class Image extends Component {
componentDidMount() {
// if image hasn't completed loading, then let react handle error
if (!this._image.complete) return;
// if image has finished loading and has 'errored'(errored when naturalWidth === 0)
// then run the onError callback
if (this._image.naturalWidth === 0) {
this.props.onError();
}
}
@hartzis
hartzis / Image.jsx
Last active April 15, 2019 23:17
react image component - utilizing recompose, handles errors
import React, { Component, PropTypes } from 'react';
import { setPropTypes, withState, lifecycle, mapProps, compose } from 'recompose';
export const ImageComponent = compose(
setPropTypes({ src: PropTypes.string.isRequired }),
withState('imgState', 'updateImgState', ({ src }) => ({ origSrc: src, currentSrc: src })),
lifecycle({
componentWillReceiveProps(nextProps) {
// if Image components src changes, make sure we update origSrc and currentSrc
if (nextProps.src !== nextProps.imgState.origSrc) {
# -------------------------------------------------------------------
# Git
# -------------------------------------------------------------------
alias ga='git add'
alias gp='git push'
alias gl='git log'
alias gs='git status'
alias gm='git commit -m'
alias gb='git branch'
alias gc='git checkout'
@hartzis
hartzis / EventComponent.js
Last active November 29, 2023 16:38
Touch Event Handling React Component
import React from 'react';
export default class EventComponent extends React.Component {
constructor(props) {
super(props);
this._onTouchStart = this._onTouchStart.bind(this);
this._onTouchMove = this._onTouchMove.bind(this);
this._onTouchEnd = this._onTouchEnd.bind(this);
@hartzis
hartzis / EventComponent.spec.js
Last active November 5, 2018 19:22
Touch Event Testing React Jest Enzyme
import React from 'react';
import EventComponent from './EventComponent';
import { mount } from 'enzyme';
import {
createStartTouchEventObject,
createMoveTouchEventObject
} from './EventHelpers.js';
describe('EventComponent', () => {