Skip to content

Instantly share code, notes, and snippets.

View jamestthompson3's full-sized avatar

jamestthompson3

View GitHub Profile
@jamestthompson3
jamestthompson3 / doom-init
Created April 6, 2018 21:48
Doom init file
;;; init.el -*- lexical-binding: t; -*-
;; Copy me to ~/.doom.d/init.el or ~/.config/doom/init.el, then edit me!
(doom! :feature
(popup ; tame sudden yet inevitable temporary windows
+all ; catch all popups that start with an asterix
+defaults) ; default popup rules
;debugger ; FIXME stepping through code, to help you add bugs
eval ; run code, run (also, repls)
(evil +everywhere); come to the dark side, we have cookies
" Don't try to be vi compatible
set nocompatible
" Helps force plugins to load correctly when it is turned back on below
filetype off
" TODO: Load plugins here (pathogen or vundle)
" Turn on syntax highlighting
syntax on
@jamestthompson3
jamestthompson3 / setObservableConfig.js
Last active January 12, 2019 13:35
RXJS and recompose demo
import { setObservableConfig } from 'recompose'
import { from, to } from 'rxjs'
setObservableConfig({ fromESOBservable: from, toESObservable: to })
import { from , to } from 'rxjs'
import { setObservableConfig, mapPropsStream } from 'recompose'
import { isEmpty } from 'lodash'
import { switchMap, map, startWith, tap, catchError } from 'rxjs/operators'
const load = mapPropsStream(props$ =>
props$.pipe(
switchMap(
props =>
isEmpty(props.userList)
const load = mapPropsStream(props$ =>
props$.pipe(
switchMap(props =>
from(fetchUsers()).pipe(
tap(res => console.log('response from fetchUsers', res),
map(users => ({ ...props, users, status: 'SUCCESS' })),
startWith({ status: 'REQUEST' })
)
),
catchError(() => ({ status: 'ERROR', message: 'Looks like our service is down' }))
import { get } from 'lodash'
import { createEventHandler } from 'recompose'
const selectUser = mapPropsStream(props$ => {
const { stream: selected$, handler: userSelect } = createEventHandler()
return props$.pipe(
switchMap(props => {
const userInURL = get(props, 'match.params.user')
return selected$
.pipe(
import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import { render } from 'react-dom'
import { from, to, of } from 'rxjs'
import { switchMap, map, startWith, tap, catchError } from 'rxjs/operators'
import {
compose,
mapPropsStream,
createEventHandler,
withState,
import { PageWrapper, ListContainer, ListItem, Loader, UserContainer } from './styledComponents'
const IndexPage = ({ status, userList, selectedUser, userSelect, message, match, history }) => {
const userParam = get(match, 'params.user')
if (selectedUser) {
userParam !== selectedUser.user && history.push(`/${selectedUser.user}`)
}
return (
<PageWrapper>
<UserContainer>
import { compose, withState, withHandlers } from 'recompose'
import { withRouter } from 'react-router-dom'
const StreamIndex = compose(
withState('userList', 'updateUserList', []),
withHandlers({ setUserList: ({ updateUserList }) => users => updateUserList(state => users) }),
withRouter,
load,
selectUser
)(IndexPage)
withHandlers({
setUserList: ({ updateUserList }) => users => updateUserList(state => users),
addLike: ({ updateUserList }) => (user, like) => addUserLike(user, like),
addDislike: ({ updateUserList }) => (user, dislike) => addUserDislike(user, dislike),
deleteLike: ({ updateUserList }) => (user, like) =>
deleteUserLike(user, like.id).then(() =>
updateUserList(state => [
...state.map(i => {
if (i.user === user) {
i.likes = i.likes.filter(i => i.id !== like.id)