mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
e9d64ebb23
* Got a hacky workspace implementation running * Removed some hax with reducer composition * Moved some more around * Moved files back out * Started on entities reducer * Split up some components * Moved nested modules back out of workspaces * Started on new Sidebar tree stuff * Better store stuff * Some more tweaks * Removed workspace update action * Re-implemented filtering in the Sidbare * Switch to get the newest response
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import {bindActionCreators} from 'redux'
|
|
import * as entitiesActions from './modules/entities'
|
|
import * as db from '../database'
|
|
|
|
const CHANGE_ID = 'store.listener';
|
|
|
|
export function initStore (dispatch) {
|
|
db.offChange(CHANGE_ID);
|
|
|
|
// New stuff...
|
|
const entities = bindActionCreators(entitiesActions, dispatch);
|
|
|
|
const docChanged = doc => {
|
|
if (!doc.hasOwnProperty('type')) {
|
|
return;
|
|
}
|
|
|
|
// New stuff...
|
|
entities[doc._deleted ? 'remove' : 'update'](doc);
|
|
};
|
|
|
|
console.log('-- Restoring Store --');
|
|
|
|
const start = Date.now();
|
|
|
|
return db.workspaceAll().then(res => {
|
|
const restoreChildren = (doc) => {
|
|
docChanged(doc);
|
|
|
|
return db.getChildren(doc).then(res => {
|
|
// Done condition
|
|
if (!res.docs.length) {
|
|
return;
|
|
}
|
|
|
|
return Promise.all(
|
|
res.docs.map(doc => restoreChildren(doc))
|
|
);
|
|
})
|
|
};
|
|
|
|
return res.docs.map(restoreChildren)
|
|
}).then(() => {
|
|
console.log(`Restore took ${(Date.now() - start) / 1000} s`);
|
|
}).then(() => {
|
|
db.onChange(CHANGE_ID, res => docChanged(res.doc));
|
|
});
|
|
}
|