insomnia/app/ui/redux/initstore.js
Gregory Schier 318c35c2cb Move a bunch of stuff to async/await (#39)
* Some minor implementations

* Some more

* Lots more

* Removed 'backend' alias

* removed all promises

* Removed a bunch of module exports stuff

* Some morE'

* Fix

* custom DNS

* Tests for DNS

* bug fix

* Some small adjustments

* Small stuff
2016-10-02 13:57:00 -07:00

33 lines
931 B
JavaScript

import {bindActionCreators} from 'redux';
import * as entitiesActions from './modules/entities';
import * as db from '../../backend/database';
export async function initStore (dispatch) {
const entities = bindActionCreators(entitiesActions, dispatch);
const handleNewChanges = entities.addChanges;
console.log('-- Restoring Store --');
const start = Date.now();
db.offChange(handleNewChanges);
// Restore docs in parent->child->grandchild order
const results = [
await db.settings.getOrCreate(),
await db.workspace.all(),
await db.environment.all(),
await db.cookieJar.all(),
await db.requestGroup.all(),
await db.request.all()
];
for (let docs of results) {
docs = Array.isArray(docs) ? docs : [docs];
handleNewChanges(docs.map(doc => [db.CHANGE_UPDATE, doc]));
}
console.log(`-- Restored DB in ${(Date.now() - start) / 1000} s --`);
db.onChange(handleNewChanges);
}