We'd like to unify our Router on both client and server and do away with the dispatcher.
This file contains hidden or 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
var forEachPromise = function (array, callback) { | |
var i = 0; | |
function iterate() { | |
if (i < array.length) { | |
callback(arrray[i]).then(function () { | |
i++; | |
iterate(); | |
}); | |
} |
This file contains hidden or 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
{ | |
"styles": [ | |
{"type": "underline", "start": 12, "end": 19}, | |
{"type": "bold", "start": 27, "end": 31} | |
], | |
"annotations": [ | |
{"nodeId": 87, "start": 27, "end": 31} | |
], | |
"links": [], | |
"offsetX": 10, |
This file contains hidden or 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
var _ = require('underscore'); | |
var escape = require('escape-html'); | |
function recur(item) { | |
var ret; | |
if (_.isObject(item) || _.isArray(item)) { | |
ret = new item.constructor(); | |
_.each(item, function (val, key) { | |
ret[key] = recur(val); | |
}); |
This file contains hidden or 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
var _ = require('underscore'); | |
var escape = require('escape-html'); | |
function ord(string) { | |
return string; | |
//return '' + string.charCodeAt(); | |
} | |
function pad(string, zeros) { | |
var count = zeros - string.length; |
This file contains hidden or 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 React, {Component} form 'react'; | |
import MyComponent from 'my-component.jsx'; // wrapped by FluxComponent | |
class ParentComponent extends Component { | |
componentDidMount() { | |
assert(this.fluxComponent.getWrapped() === this.childEl); | |
} | |
render() { | |
return <MyComponent ref={el => this.fluxComponent = el} wrappedRef={el => this.childEl = el} /> | |
} |
This file contains hidden or 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 getUser = (userId) => (dispatch, getState) => { | |
// check if we are currently fetching and return that promise | |
const fetching = getState().fetching[userId]; | |
if (fetching) { | |
return fetching; | |
} | |
// check if the user is cached | |
const cacheItem = getState().cache[userId]; | |
if (cacheItem && cacheItem.expireTime > Date.now()) { |
This file contains hidden or 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 usersReducer = (state = {users: {}, fetching: {}, cache: {}}, {type, payload}) => { | |
switch (type) { | |
case START_FETCHING: | |
return { | |
...state, | |
fetching: { | |
...state.fetching, | |
[payload.userId]: payload.promise, | |
}, | |
}; |
This file contains hidden or 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 key = generator => actionCreator => { | |
actionCreator.keyGenerator = generator; | |
return actionCreator; | |
}; |
This file contains hidden or 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 getUser = flow([ | |
key(userId => `@@getUser:${userId}`), | |
fetching(), | |
cached({ttl: 60000}), | |
])(userId => | |
api.get(`/user/${userId}`).then(user => | |
dispatch(receiveUser(user)) | |
) | |
); |
OlderNewer