Skip to content

Instantly share code, notes, and snippets.

View StevenLangbroek's full-sized avatar

Steven Langbroek StevenLangbroek

View GitHub Profile
https://csb-n419p9wnj-gecpcgsqqi.now.sh/
/**
* It's not hard to imagine JavaScript not having ternary statements,
* and having to implement these in userland. What would that look like?
* @param leftOrRight a maybe truthy value.
* @param left if truthy
* @param right otherwise
*/
function ternary(leftOrRight, left, right) {
if (leftOrRight) {
return left;
@StevenLangbroek
StevenLangbroek / community_index.jsx
Last active June 28, 2018 21:59
Parameterized routing
import React from 'react';
import { withParams } from 'next/router';
function Community(props) {
const { params, community, channel } = props;
if (Boolean(params.channelId)) {
return <ChannelPage channel={channel} />
}
import { createReducer } from 'src/utils';
const LOAD_POST = 'LOAD_POST';
const LOAD_POST_SUCCESS = 'LOAD_POST_SUCCESS';
const LOAD_POST_FAIL = 'LOAD_POST_FAIL';
const initialState = {
$isLoading: false,
$didFailLoading: false,
post: null,
"*":
core:
disabledPackages: [
"ide-flow"
"nuclide-file-tree"
"nuclide-source-control-side-bar"
"linter"
"atom-autocomplete-php"
"atom-ternjs"
]
@StevenLangbroek
StevenLangbroek / Promise.js
Created September 30, 2016 15:24
Flipped promise order.
const _then = Promise.then;
Promise.then = (error, success) => _then(success, error);
@StevenLangbroek
StevenLangbroek / 00_readme.md
Last active February 9, 2017 22:14
Validation for Redux-form

"Thunked" validation in redux-form

Validation in redux-form can be approached using many "schema-validation" libraries. I used validate.js, but ran into a restriction: we needed to validate user input differently based on other input in that same form. This is quite a common requirement for validation, and was surprisingly elegant to solve in redux-form.

small caveat: not adapted for redux-form 6

Libraries used:

import express from 'express';
import render from './react';
const app = express();
app.use(render);
import React from 'react';
import { connect } from 'react-redux';
import ProductBody from 'components/ProductBody';
import ProductImages from 'components/ProductImages';
import { openProduct } from 'reducers/product';
const ProductDetail = ({
product,
@StevenLangbroek
StevenLangbroek / 01_component.js
Last active April 20, 2016 10:34
Rather than decorators, docs recommend this pattern.
import React from 'react';
import { connect } from 'react-redux';
import ProductBody from 'components/ProductBody';
// Export named for testing
export const Product = ({
product
}) => (
<div className="product">
<h1>{product.get('title')}</h1>