Skip to content

Instantly share code, notes, and snippets.

@staydecent
staydecent / actions.js
Last active October 19, 2017 17:07
Preact Dropdown
import check from 'check-arg-types'
import createAction from '/util/createAction'
export const TOGGLE_DROPDOWN = 'TOGGLE_DROPDOWN'
const toggleDropdownAction = createAction(TOGGLE_DROPDOWN)
export function toggleDropdown (uid) {
check(arguments, ['string'])
return toggleDropdownAction({uid})
@staydecent
staydecent / modal.js
Created July 5, 2017 18:19
Modal, overlay with Preact, Portal and Glamor
import {css} from 'glamor'
import {closeModal} from '/actions'
import {Card} from '/components/elements/card'
const fadeIn = css.keyframes({
'0%': { opacity: 0 },
'100%': { opacity: 1 }
})
@staydecent
staydecent / component_props_thoughts.md
Created June 16, 2017 23:36
Thoughts on passing state down the React Component tree

What if every React component received the entire state object, and just use pipe/mapProps to get whats needed?

Or do you often pass values derived in a parent component down into a child?

And if so, what if there was a query api for defining the derived state values?

So if two components needs the same computed value of some property in the state object, they can use the same query and it can be optimized/cached there.

I’ve been getting kinda annoyed during development, where I’m like oh.. this parent component computes a value, and has all these children.. and later on I decide one of those children has a child, that needs that same computed value. Then I have to go back up the component tree and make sure I pass that value down.

@staydecent
staydecent / ramda-redux.md
Last active April 5, 2018 06:49
Ramda for all of your Redux needs

Ramda for all of your Redux needs

Ramda is a practical functional library for JavaScript programmers. While a few of the functions can be found in the JavaScript language, all of the Ramda functions are curryable and mutation free.

Ramda for your Reducer

The way I implement the Flux/Redux pattern is simply to hold a state object in a safe place -- that is a place that can only be mutated by explicit dispatching of actions. Or, explicit dispatching of instructions on how to mutate the state and return it anew.

In practice, this usually means my reducer is filled with a switch statement with very similar logic for updating, setting, or removing different nested properties on the state object.

@staydecent
staydecent / ramda-preact.js
Created May 27, 2017 05:02
Ramda over Recompose and Reselect (WIP)
const Preact = require('preact')
const atom = require('atom')
const {reducer, set, update, remove} = require('atom-lens-reducer')
const pipe = require('ramda/src/pipe')
const memoize = require('ramda/src/memoize')
const find = require('ramda/src/find')
const propEq = require('ramda/src/propEq')
const store = atom(reducer, {
@staydecent
staydecent / atom-reducer.js
Last active May 26, 2017 23:15
atom, redux, re-frame, default reducer idea (WIP)
var atom = require("atom")
// Inspiration reference:
// https://raw.githubusercontent.com/Day8/re-frame/master/images/Readme/6dominoes.png
// 1. Query - computed properties
// 2. Listen - effect handlers
// 3. Dispatch - describe mutations
// 1. Query
@staydecent
staydecent / index.js
Created May 8, 2017 23:27
requirebin sketch
const css = require('glamor')
const Preact = require('preact')
const {h, render} = Preact
css.insertRule('body { font-family: "Verdana" }')
console.log('css', css)
const Layout = () =>
h('div', {className: css.css({
@staydecent
staydecent / init.vim
Last active December 1, 2021 00:46
neovim config vim init vimrc
set nocompatible
set modelines=0
set wildcharm=<C-z>
filetype off
" save swap files globally
set directory^=$HOME/.vim/tmp//
" Tabs
@staydecent
staydecent / d3-volume-indicating-avatars.markdown
Created April 4, 2017 22:05
D3 Volume Indicating Avatars
@staydecent
staydecent / .babelrc
Last active September 6, 2018 05:28
Automatically add import declaration (to each file containing JSX) for your preferred JSX pragma
{
"presets": [
"es2015",
"react"
],
"plugins": [
"transform-es2015-spread",
"transform-object-rest-spread",
[
"./node_modules/babel-plugin-jsx-import/src/index.js",