Skip to content

Instantly share code, notes, and snippets.

@casesandberg
casesandberg / babel-regex.js
Created March 7, 2016 02:27
How can I transform file output?
export default function() {
return {
visitor: {
Program(path, { file: { code }}) {
code = transform(code)
},
},
};
}
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 🔑 Felony (PGP made easy) v0.0.1
Comment: 👀 How dafuq do I use this? --> http://felony.io 😉
xsFNBFdcTDwBEACd6x2F48mpnsWNvfXBxdFsvZfPw5D5PmN4XsDPHCHPlMXg
YZEK/PPNWKQUYkUCW7kjLRqoCwyik3uAoGTVHHIC9NaC2jOXfNTy85mLu1Hb
u4J3+RBdXOntzIvUB2I7JREYw31eSRutO9S8PNkOyzBo1JuPiX2oeolYboFv
Og7OHYvmd/Tcq0kojSgvV898rHB6a8fspbfZoJWd0Ac9bWSPmxvwyY9QG7EM
lrbd3EFlrjVBIGLxpN+BzBT3FzQGvJF98bCq3987es+7tqyf4ptAF3AOZIY0
PvblM1KusdVE1z/I14bC142OCHWfItQYXjdx5VmEfWOanLDnVl8cEC0OGeXP
@casesandberg
casesandberg / index.js
Last active October 31, 2016 23:20
Auto Scope State to Selectors in Root Reducer
//reducers/index.js
import { scopeStateToSelectors } from '../helpers/redux'
import threads, { selectors as threadsSelectors } from './threads'
...
// Scopes the state sent down to each of the selector functions by the key:
export const selectors = scopeStateToSelectors({
threads: threadsSelectors,
@casesandberg
casesandberg / server.js
Created November 7, 2016 20:35
Express + React Router
app.use(express.static('src'))
app.get('*', (request, response) => {
response.sendFile(path.resolve(__dirname, '../src', 'index.html'))
})
@casesandberg
casesandberg / list-item.js
Created December 6, 2016 18:48
reactcss playground
import React from 'react'
import reactCSS from 'reactcss'
const ListItem = ({ label, first, last, hover }) => {
const styles = reactCSS({
'default': {
item: {
marginTop: 1,
padding: 15,
background: '#333',
@casesandberg
casesandberg / keymap-manager.js
Created December 15, 2016 21:07
Dispatching Actions With Hotkeys Using Mousetrap
import Mousetrap from 'mousetrap'
export const init = (dispatch, state) => {
const keymaps = getKeymaps()
_.each(keymaps, (action, combo) => {
Mousetrap.bind(combo, () => {
dispatch(action(dispatch, state))
})
})
import React, { PropTypes } from 'react';
import { Hoverable } from '@bufferapp/redux-hover';
const MyComponent = ({
hovered, // managed by redux-hover
onMouseEnter,
onMouseLeave,
}) =>
<div
onMouseEnter={onMouseEnter}
@casesandberg
casesandberg / Popup.js
Last active April 28, 2018 10:11
Popups Managed Via Redux:
import React from 'react'
import reactCSS from 'reactcss'
import { connect } from 'react-redux'
import { actions, selectors } from './reducer'
export const Popup = ({ children, visible, onClose, name }) => {
const styles = reactCSS({
'default': {
wrap: {
position: 'absolute',
@casesandberg
casesandberg / components>tabs>Tabs.js
Last active April 18, 2017 00:49
Simplify Redux in React
import React from 'react'
import { connect } from 'react-redux'
import { store } from 'new-package'
import { reducer, path, actions, selectors } from './actions'
const Tabs ({ activeIndex, select }) => {
// Only register the reducer when tabs is used
store.register(path, reducer)
return (
@casesandberg
casesandberg / spec.js
Last active September 25, 2017 23:37
React Color Edible Input Focus Test
import { mount } from 'enzyme'
// Should Focus
const input = mount(<EdibleInput focusHexInputOnMount />);
assert(input.find('input').node === document.activeElement);
// Shouldn't Focus
const input = mount(<EdibleInput focusHexInputOnMoun={ false } />);
assert(input.find('input').node !== document.activeElement);