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 FetchData = (localStore) =>
apiClient.MakeRequestToServer()
.then(_ => localStore.dispatch(RequestSucceeded(_))
.catch(_ => localStore.dispatch(RequestFailed(_)));
...
automata
const light = faste()
.withPhases(['red', 'yellow', 'green'])
.withMessages(['tick'])
.on('tick', ['red'], ({transitTo}) => transitTo('yellow'))
.on('tick', ['yellow'], ({transitTo}) => transitTo('green'))
.on('tick', ['green'], ({transitTo}) => transitTo('red'))
.create();
export const DragMachine = faste()
.withPhases(['init', 'dragging'])
.withMessages(['mousedown', 'mouseup', 'mousemove'])
.withSignals(['up', 'down', 'move'])
// reactions
.on('mousedown', ({transitTo, emit}, event) => { emit('down', event);transitTo('dragging')}})
.on('mouseup', ({transitTo}) => transitTo('idle'))
.on('mousemove', ({emit}, event) => emit('move', event))
const light = faste()
.withPhases(['red', 'yellow', 'green'])
.withMessages(['tick'])
.withState({direction: 1})
.on('tick', ['red'], ({transitTo, setState}) => {
setState({direction: 1}); // swap!
transitTo('yellow')
})
.on('tick', ['yellow'], ({transitTo, state}) => transitTo(state.direction ? 'green' : 'red'))
@theKashey
theKashey / enzyme-await-helper.tsx
Created June 29, 2018 05:51
enzyme await `until`
import { ReactWrapper, ShallowWrapper } from 'enzyme';
export async function until<T extends (ShallowWrapper | ReactWrapper)>(
predicate: () => T,
text: string = 'until ',
timeoutDuration: number = 1000
): Promise<T> {
return new Promise<T>((resolve, reject) => {
const interval = setInterval(() => {
const result: T = predicate();
var map = new WeakMap();
var index = 0;
function weakKey(obj) {
var key = map.get(obj);
if (!key) {
key = 'weak-key-' + index++;
map.set(obj, key);
}
return key;
let counter++;
class Id extends React.Component {
state = {
id: counter++ // acquire unique id on component creating
}
render() {
this.props.children('id'+this.state.counter); // pass it down
}
}
html, body {
overflow: hidden;
}
body {
-webkit-overflow-scrolling: touch;
}
someElement.ontouchstart = (e) => {
e.preventDefault();
};