Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { TodoImmutable, Todo } from '../entities/Todo';
- import PouchDB from 'pouchdb';
- import pouchDBUpsert from 'pouchdb-upsert';
- import { fromJS } from 'immutable';
- import { CodeStatus, Action } from '../constants/constants';
- // Injection du plugin upsert dans l'api PouchDB
- PouchDB.plugin(pouchDBUpsert);
- // Déclaration de la variable de base de données
- let todoDatabase: PouchDB.Database;
- // Déclaration de la méthode d'instanciation de la base
- const getDB = () => new Promise((resolve) => {
- // 1 - Si la base n'existe pas, on la créée
- if (todoDatabase === null || todoDatabase === undefined) {
- todoDatabase = new PouchDB('TodoDB', { revs_limit: 1, auto_compaction: true });
- return resolve(todoDatabase);
- }
- else {
- // 2 - Si il y a un problème de communication avec la base, on refait l'instanciation
- todoDatabase.info().catch((err) => {
- todoDatabase = new PouchDB('TodoDB', { revs_limit: 1, auto_compaction: true });
- return Promise.resolve();
- }).then(() => {
- return resolve(todoDatabase);
- });
- }
- });
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement