Skip to content

Instantly share code, notes, and snippets.

View souhe's full-sized avatar

Jakub Kłobus souhe

View GitHub Profile
@souhe
souhe / gist:31f42469cd0dcedc56799ed551bf2dc3
Last active August 9, 2016 12:15
callstackFetch basic specification
import { createFetch } from 'callstackFetch'; // or import callstackFetch from 'callstackFetch'
const customFetch = createFetch({ // or new callstackFetch({})
onError: (parseError) => {},
onSuccess: (parsedBody) => {},
parseError: (error) => {},
parseBody: (body) => {},
parseResponseHeaders: (headers) => ({ page: headers.get('Link') }),
@souhe
souhe / test 2
Last active January 20, 2017 07:21
test2(id) {
this.test(id);
},
{
activeSelectable: ?Object;
selectables: Array<{
x: number;
y: number;
onFocus: Function;
onPress: Function;
onBlur: Function;
}>;
}
_handleKeyDown = (key: number) => {
switch (key) {
case keyCodes.up:
this._selectNewActive(x => x - 1);
break;
case keyCodes.down:
this._selectNewActive(x => x + 1);
break;
case keyCodes.center:
if (this.state.activeSelectable) {
import React, { Component } from 'react';
import { TextInput } from 'react-native';
import selectable from './selectable';
const Selectable = selectable(TextInput); // The most important line in this implementation!
export default class SelectableInput extends Component {
_input: any
export default class Buttons extends Component {
state = {
color: 'white',
}
render() {
return (
<View style={styles.container}>
<Button title="Button 1" onPress={() => this.setState({ color: 'red' })} color="red"/>
<Button title="Button 2" onPress={() => this.setState({ color: 'green' })} color="green"/>
const SelectableButton = selectable(Button);
export default class Buttons extends Component {
state = {
color: 'white',
}
render() {
return (
<View style={styles.container}>
import React, { Component } from 'react';
import Input from './Input';
import withValidation from './withValidation';
class LoginForm extends Component {
handleSubmit = () => {
const isValid = this.props.validate();
if (isValid) {
// TODO: submit data
}
@souhe
souhe / Form.jsx
Last active October 17, 2017 07:59
/* @flow */
import { PureComponent } from 'react';
type Fields = { [fieldName: string]: * };
type Props = {
children: Function,
rules: {
[fieldName: string]: (trimmedString: string) => void | string | boolean
},
/* @flow */
import React, { Component } from 'react';
...
type State = {
passwordVisable: boolean,
email: string,
password: string,