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 FetchData = (localStore) => | |
apiClient.MakeRequestToServer() | |
.then(_ => localStore.dispatch(RequestSucceeded(_)) | |
.catch(_ => localStore.dispatch(RequestFailed(_))); | |
... | |
automata |
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 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(); |
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 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)) |
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 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')) |
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 { 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(); |
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
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; |
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
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 | |
} | |
} |
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
html, body { | |
overflow: hidden; | |
} |
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
body { | |
-webkit-overflow-scrolling: touch; | |
} |
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
someElement.ontouchstart = (e) => { | |
e.preventDefault(); | |
}; |