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 jwt from 'jsonwebtoken'; | |
const data = { some: 'json' }; | |
const key = 'MuchSecretVerySecureSoSafe'; | |
jwt.sign(data, key); |
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 L = require('@7urtle/lambda'); | |
const myCurry = L.curry((a, b) => a + b); | |
const myNary = L.nary(a => b => a + b); | |
// myCurry and myNary can be called | |
// both as curried and n-ary. | |
myCurry(1)(2) === myCurry(1, 2); | |
// => true |
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
// pure function | |
// depends only on its input | |
// and produces only its output | |
const pureFunction = input => input + 1; | |
const pureFunction2 = function(input) { | |
return input + 1; | |
}; |
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 from 'react'; | |
const Page404 = () => { | |
return ( | |
<> | |
<p> | |
This is not the page that you are looking for! | |
</p> | |
</> | |
); |
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
// JavaScript functional programming | |
// Monad under 60 seconds | |
const Functor = { | |
of: value => ({ | |
value: value, | |
inspect: () => console.log(`Functor(${value})`), | |
map: fn => Functor.of(fn(value)) | |
}) | |
}; |
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
// /src/components/Wallpaper.js | |
import React, { useContext, useEffect, useState } from 'react'; | |
import { randomOf } from '@7urtle/lambda'; | |
import styled from 'styled-components'; | |
import { StoreContext } from '../store/StoreContext'; | |
const BackgroundDiv = styled.div` | |
background: ${props => 'linear-gradient(135deg, ' + props.colors[0] + ', ' + props.colors[1] + ')'}; |
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
// /src/pages/HomePage.js | |
import React, { useContext, useEffect } from 'react'; | |
import { StoreContext } from '../store/StoreContext'; | |
import { QuoteComponent, Background, Footer } from '../components'; | |
const HomePage = () => { | |
const { state, actions } = useContext(StoreContext); |
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
// /src/App.js | |
import React from 'react'; | |
import { StoreProvider } from './store/StoreContext'; | |
import HomePage from './pages/HomePage'; | |
const App = () => { | |
return ( | |
<StoreProvider> |
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
// /src/store/StoreContext.js | |
import React, { createContext, useReducer, useEffect } from 'react'; | |
import { reducer, initialState } from './reducers'; | |
import { useActions } from './actions'; | |
import { applyMiddleware } from './middleware'; | |
const StoreContext = createContext(initialState); |
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
// /src/store/middleware.js | |
import types from './types'; | |
import { getQuote } from './hooks/QuoteHook'; | |
const applyMiddleware = state => dispatch => action => { | |
switch (action.type) { | |
case types.REQUEST_RANDOM_QUOTE: | |
console.debug('[applyMiddleware]', types.REQUEST_RANDOM_QUOTE); | |
getQuote(dispatch)(action); |