Global DB is for debugging
This commit is contained in:
parent
f623fcd625
commit
3e8e4e068a
@ -9,7 +9,6 @@ import { getDatabase } from './services/db.js';
|
|||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
EventEmitter.defaultMaxListeners = 1000; // https://github.com/pouchdb/pouchdb/issues/6123
|
EventEmitter.defaultMaxListeners = 1000; // https://github.com/pouchdb/pouchdb/issues/6123
|
||||||
window.db = getDatabase();
|
|
||||||
|
|
||||||
// Attach our root view to the DOM
|
// Attach our root view to the DOM
|
||||||
createView(GalleryView, { db: getDatabase() }).mount(document.querySelector('#app'));
|
createView(GalleryView, { db: getDatabase() }).mount(document.querySelector('#app'));
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import { ImageView } from './image.js';
|
|||||||
import { LiveArray } from '../utils/livearray.js';
|
import { LiveArray } from '../utils/livearray.js';
|
||||||
|
|
||||||
export function AlbumView(vm, model) {
|
export function AlbumView(vm, model) {
|
||||||
const { remove } = model;
|
const { remove, db } = model;
|
||||||
let data = null;
|
let data = null;
|
||||||
let currentMembers = [];
|
let currentMemberLen = -1;
|
||||||
let title = null;
|
let title = null;
|
||||||
|
|
||||||
function removeImageFromAlbum(id, rev) {
|
function removeImageFromAlbum(id, rev) {
|
||||||
@ -17,18 +17,18 @@ export function AlbumView(vm, model) {
|
|||||||
const { doc, remove } = model;
|
const { doc, remove } = model;
|
||||||
const { props, members } = doc;
|
const { props, members } = doc;
|
||||||
|
|
||||||
if (title !== props.title || currentMembers.length !== members.length) {
|
if (title !== props.title || currentMemberLen !== members.length) {
|
||||||
if (data) {
|
if (data) {
|
||||||
data.cleanup();
|
data.cleanup();
|
||||||
}
|
}
|
||||||
title = props.title;
|
title = props.title;
|
||||||
currentMembers = members;
|
currentMemberLen = members.length;
|
||||||
const SELECTOR = {
|
const SELECTOR = Object.assign(
|
||||||
$or: [
|
{
|
||||||
Object.assign({ [`tags.${title}`]: { $eq: true } }, image.SELECTOR),
|
[`tags.${title}`]: { $eq: true }
|
||||||
{ _id: { $in: members } }
|
},
|
||||||
]
|
image.SELECTOR
|
||||||
};
|
);
|
||||||
|
|
||||||
data = LiveArray(db, SELECTOR);
|
data = LiveArray(db, SELECTOR);
|
||||||
data.subscribe(() => vm.redraw());
|
data.subscribe(() => vm.redraw());
|
||||||
|
|||||||
@ -76,6 +76,7 @@ export function GalleryView(vm, model) {
|
|||||||
AlbumView,
|
AlbumView,
|
||||||
{
|
{
|
||||||
doc: a,
|
doc: a,
|
||||||
|
db,
|
||||||
addTag: imageTag.add,
|
addTag: imageTag.add,
|
||||||
remove: imageTag.remove
|
remove: imageTag.remove
|
||||||
},
|
},
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export function getDatabase(name = 'gallery') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrCreate(doc) {
|
export async function getOrCreate(doc) {
|
||||||
|
const db = getDatabase();
|
||||||
try {
|
try {
|
||||||
const results = await db.get(doc._id);
|
const results = await db.get(doc._id);
|
||||||
return [results, false];
|
return [results, false];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user