In this tutorial we're going to build a set of parser combinators.
We'll answer the above question in 2 steps.
- What is a parser?
- and, what is a parser combinator?
So first question: What is parser?
| // part of a pair of functions intended to isolate code that kills the optimizing compiler | |
| // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax | |
| function functionize(func, arg) { | |
| switch (typeof func) { | |
| case 'string': | |
| return arg ? new Function(String(arg), func) : new Function(func); | |
| case 'function': | |
| return func; | |
| default: | |
| return function () {return func;}; |
| // give it a name so it reuses the same window | |
| var win = window.open(null, "redux-devtools", "menubar=no,location=no,resizable=yes,scrollbars=no,status=no"); | |
| // reload in case it's reusing the same window with the old content | |
| win.location.reload(); | |
| // wait a little bit for it to reload, then render | |
| setTimeout(function() { | |
| React.render( | |
| <DebugPanel top right bottom left > |
| Before reading: | |
| This is a soft auth check. Auth check should always be done server side, if not, your rest api are not checking correctly for auth. | |
| 1. Auth is in the store. | |
| You need to setup constants for AUTH_SET_TOKEN and AUTH_LOGOUT, | |
| then create the action creators authSetToken(token) and authLogout() action creators. | |
| Then setup a reducer that when AUTH_SET_TOKEN is dispatched, sets the internal state to {token: token}, | |
| and when logout is dispatched, clears it. | |
| Now setup a utility function isLoggedIn(state) function, that only checks in state.auth.token exists, this is a soft check. |
| let cache = new Map(); | |
| let pending = new Map(); | |
| function fetchTextSync(url) { | |
| if (cache.has(url)) { | |
| return cache.get(url); | |
| } | |
| if (pending.has(url)) { | |
| throw pending.get(url); | |
| } |