Skip to content

Instantly share code, notes, and snippets.

View lourd's full-sized avatar

Louis DeScioli lourd

View GitHub Profile
@lourd
lourd / streamSaga.test.js
Last active July 13, 2017 04:17
Example of a redux-saga saga function that uses an external emitter through an eventChannel, tested with redux-saga-test-plan
import { eventChannel } from 'redux-saga'
import { call, cps, take, fork, put, cancel, select } from 'redux-saga/effects'
function emitterChannel(emitter, eventType) {
return eventChannel(emit => {
emitter.on(eventType, emit)
return () => emitter.off(eventType, emit)
})
}
@lourd
lourd / BeforeLocationChange.js
Last active July 11, 2017 14:39
Possible component design & usage for history.before API
import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
@withRouter
class BeforeLocationChange extends Component {
static propTypes = {
history: PropTypes.shape({
before: PropTypes.func.isRequired,
}).isRequired,
handler: PropTypes.func.isRequired,
@lourd
lourd / thisLesson.js
Created July 21, 2017 17:13
Example of how "this" works in Javascript classes & functions
class Foo {
constructor() {
this.feeling = '🤥'
}
speak() {
console.log(this.feeling)
}
}