Last active
October 24, 2016 08:18
-
-
Save FeliciousX/e1096f2cef08629c1367142ef80e08a3 to your computer and use it in GitHub Desktop.
CycleJS Snippets
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 {makeHTTPDriver} from '@cycle/http'; | |
function makeCustomHTTPDriver( options ) { | |
const HTTPDriver = makeHTTPDriver( options ); | |
const token = document.querySelector('meta[name=csrf-token]').getAttribute('content'); | |
return function customHTTPDriver( sink$, streamAdapter ) { | |
const csrf_request$ = sink$.map(request => ({ | |
...request, | |
headers: { 'X-CSRF-Token' : token } | |
})); | |
const source = HTTPDriver( csrf_request$, streamAdapter ); | |
return source; | |
}; | |
} | |
export default makeCustomHTTPDriver; |
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 xs from 'xstream' | |
export default function makeLogDriver(prepend = 'DEBUG:') { | |
return function logDriver(msg$) { | |
msg$.addListener({ | |
next: function log( msg ) { | |
console.log(prepend, msg) | |
} | |
}) | |
return xs.never() | |
} | |
} |
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 xs from 'xstream' | |
export default function makePreventDefaultDriver() { | |
return function preventDefaultDriver(event$) { | |
event$.addListener({ | |
next: function preventDefault( e ) { | |
e.preventDefault(); | |
} | |
}) | |
return xs.never() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment