Skip to content

Instantly share code, notes, and snippets.

View jakerobers's full-sized avatar
🏠
Working from home

Jake Robers jakerobers

🏠
Working from home
View GitHub Profile
import assert from 'assert'
export const warn = (logger) => (msg) => {
assert(logger, `'${logger}' is not supported in this environment`)
assert(logger.warn, `'${logger}.warn' is not supported in this environment`)
logger.warn("[validate.js] " + msg)
}
import assert from 'assert'
function warn(msg) {
assert(console, '`console` is not supported in this environment')
assert(console.warn, '`console.warn` is not supported in this environment')
console.warn("[validate.js] " + msg)
}
function warn(msg) {
if (typeof console !== "undefined" && console.warn) {
console.warn("[validate.js] " + msg)
}
}
import { ServiceNotFoundError } from '../index'
import VendorAuthService from './vendorAuthService'
import MockAuthService from './mockAuthService'
const defaultEnv = process.env.NODE_ENV
const defaultIsOffline = !!process.env.REACT_APP_OFFLINE
export default function(environment = defaultEnv, offline = defaultIsOffline) {
let service
import { AuthService } from './authService'
const IS_AUTHENTICATED = process.env.REACT_APP_IS_AUTHENTICATED
export default class MockAuthService implements AuthService {
async login() {
console.info('Mocking login initialization.')
}
async logout() {
import createVendorAuthClient, { VendorAuthClient } from 'someauthservice';
import { AuthService } from './authService'
import { VendorSession, Session } from '../../models/session'
export default class VendorAuthService implements AuthService {
client: VendorAuthClient;
redirectUri: string;
constructor() {
export interface AuthService {
login(): Promise<void>;
logout(): Promise<void>;
isAuthenticated(): Promise<boolean>;
getJwtToken(): Promise<string>;
}
import _ from 'lodash/fp';
export const indexBooksByAuthor = _.keyBy('authorId');
export const getSomeValue = () => {
// some code ...
const booksByAuthor = indexBooksByAuthor(books);
// some more code ...
import _ from 'lodash';
export const indexBooksByAuthor = (books) => {
return _.reduce(books, (acc, e) => {
acc[e.authorId] = e
return acc
}, {});
}
export const getSomeValue = () => {
import _ from 'lodash';
export const getSomeValue = () => {
// some code ...
const indexed = _.reduce(books, (acc, e) => {
acc[e.authorId] = e
return acc
}, {});