Skip to content

Instantly share code, notes, and snippets.

@engineersamuel
engineersamuel / IsotopeResponseRenderer.jsx
Created January 6, 2016 13:16
componentWillReceiveProps
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});
}
}
componentDidMount() {
this.createIsotopeContainer();
// Only arrange if there are elements to arrange
if (_.get(this, 'props.children.length', 0) > 0) {
this.iso.arrange();
}
}
@engineersamuel
engineersamuel / IsotopeResponseRenderer.jsx
Created January 6, 2016 13:32
createIsotopeContainer
createIsotopeContainer() {
if (this.iso == null) {
this.iso = new Isotope(React.findDOMNode(this.refs.isotopeContainer), this.isoOptions);
}
}
render() {
return <div className="isotope" ref="isotopeContainer">
<div className="element-item-sizer"></div>
{this.props.children}
</div>
}
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);
@engineersamuel
engineersamuel / Home.jsx
Created January 6, 2016 17:59
filter and sort
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() {
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
interface IActionUpdateProductNameVersion {
productName: string;
productVersion: string;
}
const requestUpdateProductVersion = createAction<interfaces.IActionUpdateProductNameVersion, void>(types.REQUEST_UPDATE_PRODUCT_VERSION,
(productName: string, productVersion: string) => ({productName, productVersion}),
null
);
const receiveUpdateProductVersion = createAction<interfaces.IActionUpdateProductNameVersion, interfaces.IMetaIsXhrError>(types.RECEIVE_UPDATE_PRODUCT_VERSION,
@engineersamuel
engineersamuel / web.config.xml
Created May 21, 2018 22:48
Azure IIS static web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="index.html" />
</files>
</defaultDocument>
<rewrite>
<rules>
@engineersamuel
engineersamuel / event.hooks.js
Created May 21, 2018 22:53
Webpack event hook to rewrite index.html
new EventHooksPlugin({
'afterEmit': () => {
const hashedIndexHtml = glob.sync(`${paths.appBuild}/*.html`)[0];
const hash = /index\.(.*?)\.html/.exec(hashedIndexHtml)[1];
const webConfig = fs.readFileSync(`${paths.appBuild}/web.config`).toString();
const result = webConfig.toString().replace(/index\.html/g, `index.${hash}.html`);
fs.writeFileSync(`${paths.appBuild}/web.config`, result);
}
}),