Skip to content

Instantly share code, notes, and snippets.

View PeterKow's full-sized avatar
👨‍💻

Peter Kowalczyk PeterKow

👨‍💻
View GitHub Profile
@PeterKow
PeterKow / Seamless-immutable.js
Last active August 7, 2018 14:58
Seamless-immutable example
var array = Immutable(["totally", "immutable", {hammer: "Can’t Touch This"}]);
array[1] = "I'm going to mutate you!"
array[1] // "immutable"
array[2].hammer = "hm, surely I can mutate this nested object..."
array[2].hammer // "Can’t Touch This"
for (var index in array) { console.log(array[index]); }
// "totally"
module.exports = {
getTransformModulePath() {
return require.resolve("react-native-typescript-transformer");
},
getSourceExts() {
return ["ts", "tsx"];
}
};
@PeterKow
PeterKow / tsconfig.json
Created July 29, 2018 14:27
TypeScript with React Native and Jest
{
"compilerOptions": {
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es2015"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
// "declaration": true, /* Generates corresponding '.d.ts' file. */
@PeterKow
PeterKow / lint-staged + lint
Last active July 29, 2018 14:10
Lint staged
"scripts": {
...
"precommit": "lint-staged",
}
...
"lint-staged": {
"{src,test}/**/*.ts*": [
"prettier --write",
"git add"
]
@PeterKow
PeterKow / Husky + Prettier - package.json
Created July 29, 2018 12:45
Precommit Script for Husky + Prettier - package.json
{ "scripts": { "precommit": "pretty-quick --staged" } }
@PeterKow
PeterKow / React test component .spec.tsx
Created July 29, 2018 12:40
Simple test for React component
import React from 'react'
import App from './App'
import renderer from 'react-test-renderer'
describe('App', () => {
it('should render', () => {
const tree = renderer.create(<App/>).toJSON()
expect(tree).toMatchSnapshot()
})
})
@PeterKow
PeterKow / jest-config-package.json
Created July 28, 2018 11:13
Jest configuration with TypeScript and React Native
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
@PeterKow
PeterKow / tslint.json
Created July 28, 2018 11:07
Tslint for React Native
{
"extends": ["tslint:recommended", "tslint-config-prettier", "tslint-react"],
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"quotemark": [true, "single", "jsx-double"],
"ordered-imports": false,
"object-literal-sort-keys": false,
"arrow-parens": false,
"no-console": [false],
@PeterKow
PeterKow / gist:e364c71ae52ed9bfbf5636a9582f64f4
Created July 28, 2018 10:45
TypeScript with React Native
yarn add --dev typescript
yarn add --dev react-native-typescript-transformer
yarn tsc --init --pretty --jsx react
touch rn-cli.config.js
yarn add --dev @types/react @types/react-native
watchman watch-del-all
npm start -- --reset-cache