Less boilerplate when create a new reducer on Redux
Method:
'use strict'
const createReducer = (initialState, actionHandlers) => {
// @flow | |
import Relay, { graphql } from 'react-relay' | |
import { mutationCreateUpdater} from './mutationUpdater' | |
const mutation = graphql` | |
mutation createStoryMutation($input: CreateStoryInput!) { | |
createStory(input: $input) { | |
story { | |
id |
/* @flow */ | |
import { | |
forOwn, | |
size, | |
get, | |
transform, | |
noop, | |
} from 'lodash'; |
import mongoose from 'mongoose'; | |
import connectDatabase from '../src/common/database'; | |
// this is needed to load all models in mongoose.models | |
// eslint-disable-next-line | |
import * as M from '../src/models'; | |
const removeCascade = async (modelName: string, _id: string) => { | |
const modelNames = Object.keys(mongoose.models); |
// The `loader` prop is a Dataloader instance | |
// https://github.com/facebook/dataloader | |
class Dataloader extends React.Component { | |
state = {data: null, isLoaded: false}; | |
componentWillMount() { | |
this.prefetchData(this.props); | |
} | |
componentWillReceiveProps(nextProps) { | |
if (this.props.id !== nextProps.id || this.props.loader !== nextProps.loader) { | |
this.setState({isLoaded: false}); |
// Here is a function that I use all the time when creating public | |
// async APIs in JavaScript: | |
const resolvePromise = (promise, callback) => { | |
if (callback) | |
promise.then(value => callback(null, value), callback) | |
return promise | |
} | |
// Sometimes I like to use callbacks, but other times a promise is |
// using createRouteElement | |
import { Route, createRouteElement } from 'react-router' | |
const RouteWithQuery = (routeProps) => ( | |
<Route {...routeProps} render={props => ( | |
const query = parseQueryString(props.history.location.search) | |
return createRouteElement({ ...routeProps, ...props, query }) | |
)}/> | |
) |
// @flow | |
import React, { Component } from "react"; | |
import PropTypes from "prop-types"; | |
import App from "./components/App"; | |
type Props = { | |
environment: *, | |
queryTracker?: * | |
}; |
// https://hackernoon.com/redux-flow-type-getting-the-maximum-benefit-from-the-fewest-key-strokes-5c006c54ec87
// https://github.com/facebook/flow/issues/4002
// eslint-disable-next-line no-unused-vars
type _ExtractReturn<B, F: (...args: any[]) => B> = B;
export type ExtractReturn = _ExtractReturn<*, F>;
var CryptoJS = require('crypto-js'); | |
function uploadImage(uri) { | |
let timestamp = (Date.now() / 1000 | 0).toString(); | |
let api_key = 'your api key' | |
let api_secret = 'your api secret' | |
let cloud = 'your cloud name' | |
let hash_string = 'timestamp=' + timestamp + api_secret | |
let signature = CryptoJS.SHA1(hash_string).toString(); | |
let upload_url = 'https://api.cloudinary.com/v1_1/' + cloud + '/image/upload' |