Skip to content

Instantly share code, notes, and snippets.

Samuel engineersamuel

Block or report user

Report or block engineersamuel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View avoid_action_reducer.ts
interface IActionProductName { productName: string; }
interface IActionProductVersion { productVersion string; }
 
const requestUpdateProductVersion = createAction<interfaces.IActionProductName & interfaces.IActionProductVersion, void>(types.REQUEST_UPDATE_PRODUCT_VERSION,
    (productName: string, productVersion: string) => ({productName, productVersion}),
    null
);
const receiveUpdateProductVersion = createAction<interfaces.IActionProductName & interfaces.IActionProductVersion, interfaces.IMetaIsXhrError>(types.RECEIVE_UPDATE_PRODUCT_VERSION,
    (productName: string, productVersion: string) => ({productName, productVersion}),
    isXhrError
View Home.jsx
filterElements(filter, e) {
FilterSortActions.filter(filter);
}
sortElements(sort, e) {
FilterSortActions.sort(sort);
}
renderLoadButtons() {
return _.map(loadData, d => <Button key={d.name} active={this.props.type == d.value} onClick={ElementActions.loadElements.bind(this, d.value)}>{d.name}</Button>, this)
}
renderFilterButtons() {
View IsotopeResponseRenderer.jsx
componentDidUpdate(prevProps) {
// The list of keys seen in the previous render
let currentKeys = _.map(prevProps.children, (n) => n.key);
// The latest list of keys that have been rendered
let newKeys = _.map(this.props.children, (n) => n.key);
// Find which keys are new between the current set of keys and any new children passed to this component
let addKeys = _.difference(newKeys, currentKeys);
View IsotopeResponseRenderer.jsx
render() {
return <div className="isotope" ref="isotopeContainer">
<div className="element-item-sizer"></div>
{this.props.children}
</div>
}
View IsotopeResponseRenderer.jsx
createIsotopeContainer() {
if (this.iso == null) {
this.iso = new Isotope(React.findDOMNode(this.refs.isotopeContainer), this.isoOptions);
}
}
View IsotopeResponseRenderer.jsx
componentDidMount() {
this.createIsotopeContainer();
// Only arrange if there are elements to arrange
if (_.get(this, 'props.children.length', 0) > 0) {
this.iso.arrange();
}
}
View IsotopeResponseRenderer.jsx
componentWillReceiveProps(nextProps) {
if (nextProps.filter && !_.isEqual(nextProps.filter, this.props.filter)) {
this.iso.arrange({ filter: this.filterFns[nextProps.filter] || nextProps.filter });
}
if (nextProps.sort != null) {
this.iso.arrange({sortBy: nextProps.sort});
}
}
View IsotopeResponseRenderer.jsx
import React from "react";
import shallowEqual from "react-pure-render/shallowEqual"
// Flux
import connectToStores from 'alt/utils/connectToStores';
import FilterSortActions from '../flux/actions/FilterSortActions';
import FilterSortStore from '../flux/stores/FilterSortStore';
@connectToStores
export default class IsotopeResponseRenderer extends React.Component {
View IsotopeResponseRenderer.jsx
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
View IsotopeResponseRenderer.jsx
constructor(props, context) {
super(props, context);
// Copied from http://codepen.io/desandro/pen/nFrte
this.filterFns = {
// show if number is greater than 50
numberGreaterThan50: function () {
var number = $(this).find('.number').text();
return parseInt( number, 10 ) > 50;
},
You can’t perform that action at this time.