Skip to content

Instantly share code, notes, and snippets.

Avatar

Maciej Sikora maciejsikora

View GitHub Profile
View maybeMonad.ts
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
View maybeFunctor.ts
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 {
@maciejsikora
maciejsikora / Spread.js
Last active Dec 27, 2017
Change by using spread operator
View Spread.js
// 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 :)
@maciejsikora
maciejsikora / es6-module-test.js
Created Oct 23, 2017
Test file of encapsulated es6 module private resources
View es6-module-test.js
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')
@maciejsikora
maciejsikora / es6-module-test-user-module.js
Last active Oct 23, 2017
es6-module-test-user-module
View es6-module-test-user-module.js
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'
@maciejsikora
maciejsikora / universal-react-app-browser-init.js
Created Jul 30, 2017
Universal react application browser initialization
View universal-react-app-browser-init.js
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}>
@maciejsikora
maciejsikora / universal-react-app-server-rendering.js
Created Jul 30, 2017
Universal Application in React - Server Rendering Part
View universal-react-app-server-rendering.js
const renderPage = (req, res, store) => {
const reactPart = renderToString(
<Provider store={store}>
<StaticRouter
location={req.url}
context={{}}>
<App/>
</StaticRouter>
</Provider>
You can’t perform that action at this time.