Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View theKashey's full-sized avatar
🤔
what's happening?

Anton Korzunov theKashey

🤔
what's happening?
View GitHub Profile
const React = require('react');
const createFocusTrap = require('focus-trap');
const checkedProps = [
'active',
'paused',
'tag',
'focusTrapOptions',
'_createFocusTrap'
];
@theKashey
theKashey / SVG.svg
Last active January 14, 2018 00:46
SVG with fill
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theKashey
theKashey / enzyme.js
Created January 17, 2018 03:51
Enzyme 2-to-3 connector
import { mount as realMount, shallow as realShallow, render as realRender } from 'enzyme';
const proxyfy = (wrapper, settings = {}) => new Proxy(wrapper, {
get(target, prop) {
// update first
if (prop !== 'update' && !settings.child) {
if (target.update) {
target.update();
}
}
@theKashey
theKashey / Ract-redux-restate.js
Last active January 26, 2018 21:15
Why not?
import { connect } from 'react-redux';
import reduxSemaphore from 'react-redux-semaphore';
import reduxFocus from 'react-redux-focus';
// a + b = c. That a LAW!
const AddLaw = ({a, b, sum}) => <div>{a} + {b} = {sum}</div>
// ok, we will connect this component to a Redux store to get a data. Why not?
const ConnectedRender = connect(
({a, b, sum}) => ({a, b, sum})
@theKashey
theKashey / memoize-state-1-simple
Last active March 2, 2018 06:49
memoize-state cases
const addAandB = memoize( (a,b) => a + b );
addAandB(1,1)// refresh
addAandB(1,1)// memoized
addAandB(1,2)// refresh
const getVisibleTodos = (state, props) =>
switch (state.visibilityFilter) {
case 'SHOW_COMPLETED': return state.todos.filter(todo => todo.completed)
case 'SHOW_ACTIVE': return state.todos.filter(todo => !todo.completed)
default: return todos
}
const mapStateToProps = (state, props) => {
return {
todos: memoize(getVisibleTodos(state, props))
import Memoize from 'react-memoize';
<Memoize
prop1 = "theKey"
state = {this.state}
compute={ ({prop1, state}) => heavyComputation(state[prop1]) }
>
{ result => <Display>Result is: {result}</Display> }
</Memoize>
const heavyFunction = (state) => ({
a: state.a.b.c,
b: state.a.b
});
@theKashey
theKashey / dooms-day.js
Created March 29, 2018 06:48
SkyNet rocket launch
import {theDay} from 'doom-scheduler'
import {Launch} from './rocket-silo';
theDay
.then(Launch)
.then( () => alert(' :) '),
() => alert(' :( next time, you know...');
@theKashey
theKashey / dooms-day.test.js
Created March 29, 2018 11:38
dooms-day TD
import td from 'testdouble';
const {Launch} = td.replace('./rocket-silo'); // automock
const scheduler = td.replace('doom-scheduler', { theDay: Promise.resolve() })
require('./dooms-day.js');
td.verify(Launch());