Flow for all the files
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
// @flow
|
||||
import _ from 'lodash';
|
||||
import { browserHistory } from 'react-router';
|
||||
import stores from 'stores';
|
||||
|
||||
type Options = {
|
||||
baseUrl?: string,
|
||||
};
|
||||
|
||||
class ApiClient {
|
||||
constructor(options = {}) {
|
||||
baseUrl: string;
|
||||
userAgent: string;
|
||||
|
||||
constructor(options: Options = {}) {
|
||||
this.baseUrl = options.baseUrl || '/api';
|
||||
this.userAgent = 'AtlasFrontend';
|
||||
}
|
||||
|
||||
fetch = (path, method, data, options = {}) => {
|
||||
fetch = (
|
||||
path: string,
|
||||
method: string,
|
||||
data: ?Object,
|
||||
options: Object = {}
|
||||
) => {
|
||||
let body;
|
||||
let modifiedPath;
|
||||
|
||||
if (method === 'GET') {
|
||||
modifiedPath = `${path}?${this.constructQueryString(data)}`;
|
||||
if (data) {
|
||||
modifiedPath = `${path}?${data && this.constructQueryString(data)}`;
|
||||
} else {
|
||||
modifiedPath = path;
|
||||
}
|
||||
} else if (method === 'POST' || method === 'PUT') {
|
||||
body = JSON.stringify(data);
|
||||
}
|
||||
@@ -24,10 +41,12 @@ class ApiClient {
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
if (stores.user.authenticated) {
|
||||
// $FlowFixMe this is not great, need to refactor
|
||||
headers.set('Authorization', `Bearer ${stores.user.token}`);
|
||||
}
|
||||
|
||||
// Construct request
|
||||
// $FlowFixMe don't care much about this right now
|
||||
const request = fetch(this.baseUrl + (modifiedPath || path), {
|
||||
method,
|
||||
body,
|
||||
@@ -61,7 +80,7 @@ class ApiClient {
|
||||
throw error;
|
||||
})
|
||||
.then(response => {
|
||||
return response.json();
|
||||
return response && response.json();
|
||||
})
|
||||
.then(json => {
|
||||
resolve(json);
|
||||
@@ -75,17 +94,17 @@ class ApiClient {
|
||||
});
|
||||
};
|
||||
|
||||
get = (path, data, options) => {
|
||||
get = (path: string, data?: Object, options?: Object) => {
|
||||
return this.fetch(path, 'GET', data, options);
|
||||
};
|
||||
|
||||
post = (path, data, options) => {
|
||||
post = (path: string, data?: Object, options?: Object) => {
|
||||
return this.fetch(path, 'POST', data, options);
|
||||
};
|
||||
|
||||
// Helpers
|
||||
|
||||
constructQueryString = data => {
|
||||
constructQueryString = (data: Object) => {
|
||||
return _.map(data, (v, k) => {
|
||||
return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
|
||||
}).join('&');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
// https://github.com/reactjs/react-router/blob/master/docs/guides/NavigatingOutsideOfComponents.md
|
||||
import browserHistory from 'react-router/lib/browserHistory';
|
||||
export default browserHistory;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
export default (type, ...argNames) => {
|
||||
return function(...args) {
|
||||
const action = { type };
|
||||
argNames.forEach((arg, index) => {
|
||||
action[argNames[index]] = args[index];
|
||||
});
|
||||
return action;
|
||||
};
|
||||
};
|
||||
@@ -1,8 +1,9 @@
|
||||
// @flow
|
||||
import emojiMapping from './emoji-mapping.json';
|
||||
|
||||
const EMOJI_REGEX = /:([A-Za-z0-9_\-+]+?):/gm;
|
||||
|
||||
const emojify = (text = '') => {
|
||||
const emojify = (text: string = '') => {
|
||||
let emojifiedText = text;
|
||||
|
||||
emojifiedText = text.replace(EMOJI_REGEX, (match, p1, offset, string) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
import slug from 'slug';
|
||||
import marked from 'marked';
|
||||
import sanitizedRenderer from 'marked-sanitized';
|
||||
@@ -27,7 +28,7 @@ renderer.heading = (text, level) => {
|
||||
`;
|
||||
};
|
||||
|
||||
const convertToMarkdown = text => {
|
||||
const convertToMarkdown = (text: string) => {
|
||||
// Add TOC
|
||||
text = toc.insert(text || '', {
|
||||
slugify: heading => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const randomInteger = (min, max) => {
|
||||
// @flow
|
||||
const randomInteger = (min: number, max: number) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable */
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
|
||||
const snap = children => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
@@ -121,7 +122,7 @@ function generate(str, options) {
|
||||
* toc
|
||||
*/
|
||||
|
||||
function toc(str, options) {
|
||||
function toc(str: string, options: Object) {
|
||||
return generate(str, options).toc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user