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
class Just<Data> { | |
value: Data; | |
constructor(value: Data) { | |
this.value = value | |
} | |
fmap<NextData>(f: (x: Data) => NextData) { | |
return new Just<NextData>(f(this.value)) | |
} | |
private flat() { | |
return this.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
class Just<Data> { | |
value: Data; | |
constructor(value: Data) { | |
this.value = value; | |
} | |
fmap<NextData>(f: (x: Data) => NextData) { | |
return new Just<NextData>(f(this.value)) | |
} | |
} | |
class Nothing { |
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
// object | |
const claraFrog = { color: 'green', name: 'Clara' }; | |
const juliaFrog = { ...claraFrog, name: 'Julia' }; | |
// array | |
const week = ['monday','tuesday','wednesday','thursday','friday','saturday', 'sunday']; | |
const betterWeek = [...week]; | |
betterWeek.shift(); // week without monday :) |
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 assert = require('assert') | |
const rewire = require('rewire') | |
// standard using of exported functions | |
const { createUser } = require('./user') | |
// using rewire to get into private resources | |
const userRewire = rewire('./user') | |
const hasProp = userRewire.__get__('hasProp') | |
const hasProps = userRewire.__get__('hasProps') |
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
function hasProp (obj, prop) { | |
return obj.hasOwnProperty(prop) | |
} | |
function hasProps (obj, props) { | |
return props.filter(prop => hasProp(obj, prop)).length === props.length | |
} | |
function isString (value) { | |
return typeof value === '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 initState = window.__STATE__; | |
delete window.__STATE__; // not needed anymore | |
// Create Redux store with initial state | |
const store = createStore(reducer.main, initState); | |
// start the app | |
window.initApp = (url) => { | |
window.onload = () => { | |
ReactDOM.render( | |
<Provider store={store}> |
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 renderPage = (req, res, store) => { | |
const reactPart = renderToString( | |
<Provider store={store}> | |
<StaticRouter | |
location={req.url} | |
context={{}}> | |
<App/> | |
</StaticRouter> | |
</Provider> |