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 -- | |
// In this first exmaple, the action dispatching and flow would be hard to test, because its highly coupled with | |
// the component and the way it interacts with the Linking API. | |
// login.js | |
import {Linking} from 'react-native' | |
export default class Login extends Component { | |
constructor(props) { | |
super(props); | |
this.handleDeepLink = this.handleDeepLink.bind(this); |
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
// Recursive funcion with Tail Call Optimization | |
flatten = ([first, ...rest], work = []) => { | |
if (first === undefined) { | |
return work; | |
} | |
else if (!Array.isArray(first)) { | |
return flatten(rest, [...work, first]); | |
} | |
else { |
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
// tpr = tiles per row | |
const calcTileDimensions = (deviceWidth, tpr) => { | |
const margin = deviceWidth / (tpr * 10); | |
const size = (deviceWidth - margin * (tpr * 2)) / tpr; | |
return { size, margin }; | |
}; |
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, { Component } from 'react'; | |
import { Text, View, StyleSheet, Dimensions } from 'react-native'; | |
const { width } = Dimensions.get("window"); | |
export default class App extends Component { | |
render() { | |
const tileDimensions = calcTileDimensions(width, 2) // -> change this number and see! | |
const tiles = 'Lorem Ipsum Dolor Sit Amet'.split(' ') | |
return ( | |
<View style={styles.container}> |
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
// This goes after https://gist.github.com/DrBoolean/3f5ac08a5bf1c4673757 | |
const setNameActionCretor = name => ({ type: "SET_NAME", payload: { name } }); | |
const setName = localStorage | |
.chain(ls => safeProp("user", ls)) | |
.chain(u => safeProp("name", u)) | |
.map(n => n.toUpperCase()) | |
.chain(printLn) | |
.map(m => m.toLowerCase()) |
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
sendNotification = function(data) { | |
var headers = { | |
"Content-Type": "application/json; charset=utf-8", | |
Authorization: "Basic NzkwODdjM2YtODMxNi00ODMyLTgwMWEtZTVkOTcyMzg4ZWRi" | |
}; | |
var options = { | |
host: "onesignal.com", | |
port: 443, | |
path: "/api/v1/notifications", |
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
// updateKeys :: (String -> String) -> Object -> Object | |
const updateKeys = f => | |
R.compose(R.fromPairs, R.map(R.over(R.lensIndex(0), f)), R.toPairs); | |
// updateKeysWithMap :: Object -> Object -> Object | |
const updateKeysWithMap = map => updateKeys(k => map[k] || k); | |
// example: | |
updateKeysWithMap({ oldKey: "newKey" })({ oldKey: 2 }); // -> { newKey: 2 } |
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 concatMany = unapply(unnest) | |
concatMany([1,2,3], [4,5,6], [7,8,9]) | |
// -> [1, 2, 3, 4, 5, 6, 7, 8, 9] |
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 isType = R.curry((type, value) => R.type(value) === type); | |
const rules = { | |
version: [[isType('Number')], 'Version must be a number'], | |
build: [[isType('Number')], 'Build must be a number'], | |
appName: [[isType('String'), 'appName must be a string']] | |
} |
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 typeMessage = (type, field) => `${field} has to be a ${type}`; | |
const typeRule = type => [ | |
isType(type), | |
(val, field) => typeMessage(type, field) | |
]; | |
const isString = typeRule("String"); | |
const isNumber = typeRule("Number") | |
const rules = { | |
version: [isNumber], |
OlderNewer