This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
export default (options, WrappedComponent) => class extends React.Component { | |
constructor () { | |
super() | |
this.validate = options.validate | |
this.state = options.fields.reduce((result, field) => { | |
result.fields.push(field) | |
result.errors[field] = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test from 'tape'; | |
import { put, call } from 'redux-saga/effects' | |
import { changeLOS } from './sagas' | |
import api from 'nowhere' | |
test('changeLOS Saga', assert => { | |
const gen = changeLOS() | |
assert.deepEqual( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTimeOfDay (start, end) { | |
if (start < 12 && end > 16) { return null } // not specific enough | |
// we don't care about the window from 22:00 - 06:00 | |
const timesOfDay = Array(24) | |
.fill('Morning', 6, 12) | |
.fill('Afternoon', 12, 16) | |
.fill('Evening', 16, 22) | |
return Array.from(new Set(timesOfDay.slice(start, end))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function () { | |
let className = '' | |
let options = {} | |
const classNames = [] | |
if (arguments.length > 1) { | |
className = arguments[0] | |
options = arguments[1] | |
classNames.push(className) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// must run in a context where Immutable is available, like in the console here: https://facebook.github.io/immutable-js/docs/#/ | |
const flattenList = items => { | |
return items.reduce((result, item) => { | |
result = result.push(item) | |
return item.has('children') ? result.concat(flattenList(item.get('children'))) : result | |
}, Immutable.List()) | |
} | |
const nestedList = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (reducerMap = {}, initialState) => | |
(state = initialState, { type = '', ...payload }) => | |
(reducerMap[type] || (() => state))(state, payload) // if type isn't found in the reducer, just use a noop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
export default options => { | |
return WrappedComponent => class FormValidation extends React.Component { | |
constructor () { | |
super() | |
this.validate = options.validate | |
this.cachedFunctions = { onChange: {}, onBlur: {} } | |
this.state = options.fields.reduce((result, field) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
s = status | |
d = diff | |
c = checkout | |
co = commit | |
ps = push | |
l = log | |
p = pull | |
b = branch | |
[user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render, fireEvent } from 'react-testing-library' | |
import useValidation from '..' | |
describe('use-validation', () => { | |
const Test = ({ mockFunc, handleSubmit }) => { | |
const { fields } = useValidation({ | |
fields: { | |
foo: '', | |
bar: '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I like how this approach lets me test my hook as if it's a pure function, | |
// but something about this feels weird 🤔 🤫 | |
test('use-validation', () => { | |
let counter = 0 | |
render( | |
<Test> | |
{fields => { | |
const fooFuncs = { | |
onChange: fields.foo.onChange, |
OlderNewer