Skip to content

Instantly share code, notes, and snippets.

View kennetpostigo's full-sized avatar
🏠
Working from home

Kennet Postigo kennetpostigo

🏠
Working from home
View GitHub Profile
@kennetpostigo
kennetpostigo / Migrating.md
Last active June 2, 2021 17:44
How I migrated from ReactRouter v2 to v4

First couple things I thought about when migrating after reading the docs

So migrating my existing app wasn't as troublesome as I originally thought. First thing I did was take a look at my router and routes and figure try to make a mental model of all the files where I had nested routes in the existing app because those components/containers will contain {this.props.children}. So I need to replace those with the nested <Match /> components.

So just to give an example:

In v2:

<Router history={history}>
  <Route path="/" component={App}>
@kennetpostigo
kennetpostigo / ReasonBSTADTNPM.re
Last active October 8, 2019 03:54
Reason BST Primer for Blog Post algebraic data types + pattern matching
type worker = {
name: string,
age: int,
};
type workStatus =
| Unemployed(worker)
| Fulltime(worker)
| Parttime(worker);
@kennetpostigo
kennetpostigo / NotAbstract.re
Created July 19, 2018 21:59
NotAbstract example from Universal and Existential Types in ReasonML blogpost
/* link to playground: https://bit.ly/2uCBISK */
module type Animal = {
type t = string;
let make: (string) => t;
let sprint: (t) => string;
};
module Animal: Animal = {
type t = string;
let make = (name) => name;
@kennetpostigo
kennetpostigo / ExistentialExample.re
Last active July 19, 2018 21:56
ExistentialTypesExample from Universal and Existential Types blog post
/* link to playground: https://bit.ly/2uP4SgO */
module type Animal = {
type t;
let make: (string) => t;
let sprint: (t) => string;
};
module Animal: Animal = {
type t = string;
let make = (name) => name;
@kennetpostigo
kennetpostigo / ReasonBSTFull.re
Created June 25, 2018 15:30
Reason BST Blog Post full implementation
type binarySearchTree('a) =
| Empty
| Node(node('a))
and node('a) = {
value: 'a,
left: binarySearchTree('a),
right: binarySearchTree('a),
};
let compare = (f, s) =>
@kennetpostigo
kennetpostigo / ReasonBSTVariant.re
Last active June 26, 2018 15:32
Reason BST Blog Post variants
/* pet is called a type constructor. Dog, Cat, and
Hamster are called value constructors or tags*/
type pet =
| Dog
| Cat
| Hamster;
/* myPet is of type pet */
let myPet = Dog;
@kennetpostigo
kennetpostigo / ReasonBSTTypes.re
Last active June 25, 2018 14:56
Reason BST Blog Post types
/* waddup annotated as a string */
let waddup: string = "waddup fam?!?!";
/* greeting annotated as a function that takes a string and returns string */
let greeting: string => string = name => "Hey " ++ name ++ "!";
/* Type constructor for a function that takes a string and returns unit */
type nonPureGreeting = string => unit;
/* printGreet annotated as nonPureGreeting*/
@kennetpostigo
kennetpostigo / ReasonBSTPM.re
Created June 24, 2018 14:34
Reason BST Blog Post pattern matching
type pets =
| Dog(string)
| Cat(string)
| Hamster(string);
let myPet = Dog("Buddy");
switch (myPet) {
| Dog(name) => "I have a Dog " ++ name ++ "!"
| Cat(name) => "I have a Cat " ++ name ++ "!"
@kennetpostigo
kennetpostigo / ReasonBSTPMS.re
Created June 24, 2018 14:33
Reason BST Blog Post pattern matching syntax
/* Typical pattern matching with a switch */
switch (expression) {
| pattern1 => expression1
| pattern2 => expression2
| ...
| patternN => expressionN
};
/* Typical destructuring for tuple*/
let (x, y) = tupleOfXY;
@kennetpostigo
kennetpostigo / ReasonBSTRecords.re
Created June 24, 2018 14:30
Reason BST Blog Post records
type dog = {
name: string,
breed: string,
age: int
};
let myFirstDog = {
name: "Bubbly",
breed: "Poodle",
age: 3