Skip to content

Instantly share code, notes, and snippets.

// Runs resetError() AFTER storeToken(token)
export function renewToken({ clientId, redirectUri }) {
return (dispatch, getState) => {
getOAuthToken({ clientId, redirectUri })
.then(token =>
dispatch(storeToken(token))
)
.then(() => {
dispatch(resetError());
});
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import flow from 'lodash/flow';
import { FormattedMessage } from 'react-intl';
import { storeToken } from '../actions/securityActions';
import { resetError } from '../actions/errorsActions';
import { setCampaign } from '../actions/campaignActions';
// Must be defined before thunk
const promiseCatcher = store => next => action => {
if (typeof action !== 'function') {
return next(action);
}
const decoratedAction = (dispatch, getState) => {
const p = action(dispatch, getState);
return Promise.resolve(p).then(err => console.log(action));
};
return next(decoratedAction);
function Foo() {
const onSearch = () => { console.log('search woo') };
const onResponse = () => { console.log('response woo')};
return (
<div className="field">
<View
className="auto-complete"
onSearch={onSearch}
onResponse={onResponse}
/>
.catch(getErrorFromResponse(formatMessage({ id: 'messages.actions.folder.create.failure.message' })))
.catch(errorMsg =>
showErrorMessage({
title: formatMessage({ id: 'messages.actions.folder.create.failure.title' }),
content: errorMsg,
}) && Promise.reject(errorMsg)
);
export const getErrorFromResponse = defaultMessage => error =>
error.response.json().then(error => {
try {
return Promise.reject(error.error.exception[0].message)
} catch (e) {
return Promise.reject(defaultMessage)
}
});
@lmatteis
lmatteis / dotfiles
Created October 12, 2016 07:53
dotfiles
'body':
'ctrl-tab ^ctrl': 'unset!'
'ctrl-tab': 'pane:show-next-item'
'ctrl-shift-tab ^ctrl': 'unset!'
'ctrl-shift-tab': 'pane:show-previous-item'
set tabstop=2 " tab width is 4 spaces
set shiftwidth=2 " indent also with 4 spaces
set expandtab
syntax on " syntax highlighting
overviewAction(self.parameters)
.then(function (response) {
console.log('overview: ', response)
self.overviewData = response.value[0];
return topMentionsHashtagsAction(self.parameters)
})
.then(function (response) {
console.log('top: ', response.value)
self.topHashtags = response.value.hashtags.slice(1, 3)
self.topMentions = response.value.mentions.slice(1, 3)
@lmatteis
lmatteis / cyclejs-idea.js
Last active August 27, 2016 17:06
Treating "cycle apps" as drivers
// github-cycle.js
function main (sources) {
let request$ = sources.props$
.map((prop) => {
url: 'http://github.com/api/' + prop,
})
let response$ = sources.HTTP
.flatten();
{
id: message.r.id,
host: node.host || node.address,
port: node.port,
token: message.r.token
}