This file contains hidden or 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 events = [ 'domLoading', 'domInteractive', 'domContentLoadedEventEnd', 'domComplete', 'loadEventEnd' ]; | |
| const startEvent = 'navigationStart'; | |
| const timing = performance.timing; | |
| const compose = (f, g) => x => f(g(x)); | |
| const timeFromNavigationStart = event => differenceInSeconds(timing[event], timing[startEvent]); | |
| const differenceInSeconds = (t1, t2) => (t1 - t2) / 1000; | |
| const sanitizeTime = t => (t > 0) ? t : 'N/A - Has not fired yet - please run console log again'; |
This file contains hidden or 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
| { | |
| "listing": { | |
| "features": { | |
| "bedrooms": { | |
| "value": 3 | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or 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 Features = ({ bedrooms, bathrooms }) => ( | |
| <div> | |
| <span>Beds: </span><span>{ bedrooms }</span> | |
| <span>Baths: </span><span>{ bathrooms }</span> | |
| </div> | |
| ); |
This file contains hidden or 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 ComponentThatWrapsFeatures = ({ data }) => { | |
| const features = getFeatures(data); | |
| return features && <Features {...features} /> | |
| }; |
This file contains hidden or 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 Option = x => (x === undefined || x === null) ? None : Some(x); | |
| const Some = x => ({ | |
| map: f => Some(f(x)), | |
| flatMap: f => f(x), | |
| fold: (ifEmpty, f) => f(x) | |
| }); | |
| const None = { | |
| map: f => None, |
This file contains hidden or 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 getBedrooms = data => | |
| Option(data.listing) | |
| .flatMap(listing => Option(listing.features)) | |
| .flatMap(features => Option(features.bedrooms)) | |
| .map(bedrooms => bedrooms.value) | |
| .fold(() => 0, v => v); | |
This file contains hidden or 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 Left = x => ({ | |
| map: f => Left(x), | |
| fold: (ifLeft, ifRight) => ifLeft(x) | |
| }); | |
| const Right = x => ({ | |
| map: f => Right(f(x)), | |
| fold: (ifLeft, ifRight) => ifRight(x) | |
| }); |
This file contains hidden or 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 getUserFromLocalStorage = keyName => { | |
| const str = localStorage.getItem(keyName); | |
| return JSON.parse(str); | |
| }; |
This file contains hidden or 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 doSomethingWithUserData = () => { | |
| const cage = getUserFromLocalStorage('cage'); | |
| // do wonderful things | |
| }; |
This file contains hidden or 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 getUserFromLocalStorage = keyName => { | |
| const str = localStorage.getItem(keyName); | |
| try { | |
| return JSON.parse(str); | |
| } catch (e) { | |
| return "Invalid or Corrupted User Data"; | |
| } | |
| }; |