Skip to content

Instantly share code, notes, and snippets.

export type FormsState = {
+user: {
+initialState: UserForm,
+changedState: { +[id: Id]: UserForm },
},
};
export type State = {
+forms: FormsState,
};
export type UserForm = {
+name: string,
+description: string,
+likesCats: boolean,
+likesDogs: boolean,
+gender: null | 'male' | 'female' | 'other',
+wantsKing: boolean,
};
@steida
steida / typed.js
Created December 6, 2016 04:35
Typed shit
/* @flow */
import type { Style, Theme } from '../themes/types';
import React from 'react';
import { createComponent } from 'react-fela';
// TODO:
// Exact<PropType> on Component props.
// Text.style(props) should by typed.
// Text.Props like React.Element, how React does it?
// Autocomplete for props.
@steida
steida / prefetch.jsx
Created November 6, 2016 21:07
Eagerly prefetch any component. Simple stupid.
<Link to={`/people/${viewer.id}`}>
<div style={{ display: 'none' }}>
<ProfilePage params={{ id: viewer.id }} />
</div>
<FormattedMessage {...messages.yourPublicProfile} />
</Link>
// TODO: Run epic on app start if geolocation was already explicitly requested.
const watchAppPositionEpic = (action$, { geolocation }) => {
const geolocation$ = Observable.create(observer => {
const onNext = (position: Position) => {
const action = watchAppPositionNext(geopositionToObject(position));
observer.next(action);
};
const onError = ({ code, message }: PositionError) => {
const action = watchAppPositionFail({ code, message });
observer.next(action);
@steida
steida / Root.jsx
Created September 15, 2016 00:09
React Router 4 workaround for Link, Match, etc. inside pure component or Redux connect.
import BrowserHistory from 'react-history/BrowserHistory'
import React from 'react';
import Test from './Test';
import { Provider as Redux } from 'react-redux';
import { StaticRouter } from 'react-router';
import { connect } from 'react-redux';
import { setLocation } from '../../common/app/actions';
// Some component wrapped by pure container.
const Test = (props) => (
@steida
steida / OfflinePage.react.jsx
Last active August 19, 2016 10:10
Stateless functional component with decorators (not available yet)
import Helmet from 'react-helmet';
import React from 'react';
import linksMessages from '../../common/app/linksMessages';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { fields } from '../../common/lib/redux-fields';
@fields({
path: 'offline',
fields: [
@steida
steida / OfflinePage.react.jsx
Created August 16, 2016 23:35
React stateless functional component with higher order component wrappers.
import Helmet from 'react-helmet';
import React from 'react';
import linksMessages from '../../common/app/linksMessages';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { fields } from '../../common/lib/redux-fields';
let OfflinePage = ({ fields, online }) => (
<div className="offline-page">
<FormattedMessage {...linksMessages.offline}>
import { BaseError } from 'make-error';
export default class ValidationError extends BaseError {
constructor(name, params = {}) {
super(`ValidationError: ${JSON.stringify({ name, params })}`);
this.name = name;
this.params = params;
}
export const validateEmailAndPassword = (validate, fields) => validate(fields)
.prop('email')
.required()
.email()
.prop('password')
.required()
.simplePassword()
.promise;