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 AppDispatcher from 'AppDispatcher'; | |
| import when from 'when'; | |
| function asyncDispatch(actionType, promise, actionObj = {}) { | |
| AppDispatcher.handleViewAction({ | |
| type: actionType.LOADING | |
| }); | |
| return promise.then(response => { | |
| AppDispatcher.handleViewAction({...{ |
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
| function resolveUrl() { | |
| return [...arguments] | |
| .map(function stripArgument(argument, index) { | |
| if (argument[argument.length - 1] === '/') { | |
| return stripArgument(argument.slice(0, argument.length - 1), index); | |
| } | |
| if (index !== 0 && argument[0] === '/') { | |
| return stripArgument(argument.slice(1, argument.length), index); | |
| } |
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
| function objectToGetParams(object) { | |
| const params = Object.keys(object) | |
| .filter(key => !!object[key]) | |
| .map(key => `${key}=${encodeURIComponent(object[key])}`) | |
| .join('&'); | |
| return params.length ? '?' + params : ''; | |
| } |
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
| function BEMBlockModifier(blockName = '', modifiers = {}) { | |
| return (blockName + ' ' + Object.keys(modifiers) | |
| .map(key => !!modifiers[key] ? `${blockName}--${key}` : '') | |
| .join(' ')) | |
| .replace(/\s\s+/g, ' ') | |
| .trim(); | |
| } |
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
| function connectToStore(Store, mapStateToProps) { | |
| const requiredStoreMethods = ["addChangeListener", "removeChangeListener"]; | |
| requiredStoreMethods.forEach(method => { | |
| if (!Store.hasOwnProperty(method)) { | |
| throw new Error(`Attempted to connect to a store without ` | |
| + `${method} method`); | |
| } | |
| }); |
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 from "react"; | |
| const defaultConfig = { | |
| addChangeListener: "addChangeListener", | |
| removeChangeListener: "removeChangeListener", | |
| }; | |
| function validateStoreMappings(storeMappings, config) { | |
| if (!storeMappings) { | |
| throw new Error("No storeMappings provided."); |
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
| function uid() { | |
| return Math.random().toString(36).substr(2, 9); | |
| } |
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
| function promiseRetrier(func, config = {}) { | |
| const options = { | |
| timeout: 1000, | |
| ...config, | |
| }; | |
| let retries = 0; | |
| return function retry(...args) { | |
| return func(...args).then(res => res, err => { |
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
| function promiseCache(ttl, method) { | |
| const updated = {}; | |
| const results = {}; | |
| return key => (...args) => { | |
| const keyUpdated = updated[key]; | |
| if (keyUpdated === undefined || ((keyUpdated + ttl) <= Date.now()) || !results[key]) { | |
| return method(...args).then(res => { | |
| updated[key] = 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 flattenObj = (obj, join = '.') => { | |
| const toReturn = {}; | |
| for (const i in obj) { | |
| if (!obj.hasOwnProperty(i)) { | |
| continue; | |
| } | |
| if ((typeof obj[i]) === 'object') { | |
| const flatObject = flattenObj(obj[i]); |
OlderNewer