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
// One must love Dan: | |
// https://github.com/reduxjs/react-redux/issues/1252#issuecomment-488160930 | |
// bindActionCreators are not good for your codebase!? | |
const useInfo = journey => { | |
const dispatch = useDispatch(); | |
return { | |
goToStep: useCallback((...args) => dispatch(goToStep(...args)), [dispatch]), | |
goToNextStep: useCallback((...args) => dispatch(goToNextStep(...args)), [dispatch]), |
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
// Did you know that in @validarium you can combine not only validation schemes | |
// (as is used in `validate` fn), but even the particular validations? | |
import { validate, createValidation, combineValidate } from '@validarium/core'; | |
// 1. For the example I am using one of the validation from @validarium/validations: | |
import { hasNoSpecialSymbols } from '@validarium/validations'; | |
import { test } from 'ramda'; | |
import m from './messages'; |
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
// BEFORE: | |
const CommentTextArea = ({ maxCharacters, name, validate, ...otherProps }) => ( | |
<TextareaField | |
name={name} | |
rows={4} | |
label={<Message {...messages.comment} />} | |
maxCharacters={maxCharacters} | |
{...otherProps} | |
/> | |
); |
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
const Example = ({ onClick }) => { | |
const memoizedHandleClick = useCallback( | |
(event) => onClick(event), | |
[] // ugly magic of hooks | |
); | |
return <Button onClick={memoizedHandleClick}>Click</Button>; | |
} |
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() { | |
// good opportunity to combine into a single statement | |
// qq w cw <esc> A, <esc> 0 j q | |
var a = 10; | |
var b = 20; | |
var c = 30; | |
var d = 40; | |
var e = 50; | |
// opportunity to simplify syntax |
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, { useMemo } from 'react'; | |
const Section = ({ heading, children }) => { | |
const headingChild = useMemo(() => <h1>{heading}</h1>, [heading]); | |
return ( | |
<section> | |
{headingChild} | |
{children} | |
</section> |
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 { curry, apply } from 'ramda'; | |
/** | |
* Debounce | |
* | |
* @param {Boolean} immediate If true run `fn` at the start of the timeout | |
* @param timeMs {Number} Debounce timeout | |
* @param fn {Function} Function to debounce | |
* | |
* @return {Number} timeout |
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 { modulo, o, not, curry, compose, length, filter, split, map } from 'ramda'; | |
// Number -> Number | |
const isOdd = o(Boolean, modulo(2)); | |
// Number -> Boolean | |
const isEven = o(not, isOdd); | |
// (a -> Boolean) -> [a] -> Number | |
const countIf = curry(compose(length, filter)); |