Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (dispatch) => {
// Announce gene request from cache/server,
// add genes to fetchingGenes to indicate
// they are being fetched
dispatch(requestGenesFetch(unfetched, path, title));
let cacheKeys = new Array(unfetched.length);
for (let i = 0; i < unfetched.length; i++) {
cacheKeys[i] = path + '/' + unfetched[i];
}
// try loading from cache
localforage.getItems(cacheKeys)
// store all genes retrieved from cache
.then((retrievedGenes) => {
let cachedNames = [],
cachedGenes = {},
keys = Object.keys(retrievedGenes) ;
for (let i = 0; i < keys.length; i++) {
let gene = retrievedGenes[keys[i]];
// each key that is uncached returns as an
// undefined entry in this array
if (gene) {
cachedGenes[gene.name] = gene;
cachedNames.push(gene.name);
}
}
if (cachedNames.length) {
// the overlapping names are the cached names
componentDidMount = () => {
if (
this.slateEditor &&
this.slateEditor.value &&
!this.slateEditor.state.value.hasUndos
) {
/**
* Finds all used image keys in the document.
* @const contentImageKeys
*/
const contentImageKeys = this.slateEditor.value
.toJSON()
.document.nodes.filter(node => !!(node.data && node.data.key))
.map(node => node.data.key)
localForage.getItems().then(storedImageKeys => {
/**
* Creates a list of image keys in the database which aren't part of the content.
* @var unusedImageKeys
*/
let unusedImageKeys = []
Object.keys(storedImageKeys).forEach(storedKey => {
let unused = true
contentImageKeys.forEach(usedKey => {
if (storedKey === usedKey) {
unused = false
}
})
unused && unusedImageKeys.push(storedKey)
})
unusedImageKeys.forEach(imageKey => {
localForage.removeItem(imageKey)