Allow Watcher Re-use to cut down on memory pressure.
This commit is contained in:
parent
6b0cfc0d2e
commit
f623fcd625
@ -12,7 +12,7 @@ EventEmitter.defaultMaxListeners = 1000; // https://github.com/pouchdb/pouchdb/i
|
||||
window.db = getDatabase();
|
||||
|
||||
// Attach our root view to the DOM
|
||||
createView(GalleryView, {}).mount(document.querySelector('#app'));
|
||||
createView(GalleryView, { db: getDatabase() }).mount(document.querySelector('#app'));
|
||||
|
||||
// Start the router
|
||||
router.start('home');
|
||||
|
||||
@ -6,23 +6,27 @@ import { ImageView } from './image.js';
|
||||
import { AlbumView } from './album.js';
|
||||
import { router, routeChanged } from '../services/router.js';
|
||||
import { LiveArray } from '../utils/livearray.js';
|
||||
|
||||
const NAV_OPTIONS = {
|
||||
images: {
|
||||
selector: image.SELECTOR,
|
||||
title: 'Images'
|
||||
},
|
||||
albums: {
|
||||
selector: index.SELECTOR,
|
||||
title: 'Albums'
|
||||
}
|
||||
};
|
||||
import { Watcher } from '../utils/watcher.js';
|
||||
|
||||
function uploadImages(evt) {
|
||||
image.add(evt.currentTarget.files);
|
||||
}
|
||||
|
||||
export function GalleryView(vm, model) {
|
||||
const { db } = model;
|
||||
const NAV_OPTIONS = {
|
||||
images: {
|
||||
selector: image.SELECTOR,
|
||||
watcher: image.watcher,
|
||||
title: 'Images'
|
||||
},
|
||||
albums: {
|
||||
selector: index.SELECTOR,
|
||||
watcher: Watcher(db, index.SELECTOR),
|
||||
title: 'Albums'
|
||||
}
|
||||
};
|
||||
|
||||
let data = null;
|
||||
let title = '';
|
||||
|
||||
@ -31,7 +35,7 @@ export function GalleryView(vm, model) {
|
||||
data.cleanup();
|
||||
}
|
||||
const o = NAV_OPTIONS[route.name];
|
||||
data = LiveArray(db, o.selector);
|
||||
data = LiveArray(db, o.selector, o.watcher);
|
||||
title = o.title;
|
||||
data.subscribe(() => vm.redraw());
|
||||
});
|
||||
|
||||
@ -2,8 +2,8 @@ import { observable, computed } from 'frptools';
|
||||
import { group, groupEnd, log } from '../services/console.js';
|
||||
import { Watcher } from './watcher.js';
|
||||
|
||||
export function LiveArray(db, selector) {
|
||||
const watcher = Watcher(db, selector);
|
||||
export function LiveArray(db, selector, watcher) {
|
||||
const _watcher = watcher || Watcher(db, selector);
|
||||
const data = observable({ docs: [] });
|
||||
const docs = computed(r => r.docs, [data]);
|
||||
let changeSub = null;
|
||||
@ -28,7 +28,7 @@ export function LiveArray(db, selector) {
|
||||
}
|
||||
|
||||
refresh().then(() => {
|
||||
changeSub = watcher(refresh);
|
||||
changeSub = _watcher(refresh);
|
||||
accessor.ready(true);
|
||||
});
|
||||
return accessor;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user