Timothy Farrell faa3c48c99 Redo LiveArray to watch all returned IDs for removal from the selector.
There is still a big TODO here in that the globalWatcher mechanism assumes one database.  Need to re-structure this whole thing around a db instance.
2017-11-02 08:38:13 -05:00

42 lines
1.1 KiB
JavaScript

import { readAsArrayBuffer } from 'pouchdb-binary-utils';
export function bufferToHexString(buffer) {
const hexCodes = [];
const view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
const value = view.getUint32(i);
// toString(16) will give the hex representation of the number without padding
// We use concatenation and slice for padding
hexCodes.push(`00000000${value.toString(16)}`.slice(-8));
}
// Join all the hex strings into one
return hexCodes.join('');
}
export function blobToArrayBuffer(blob) {
return new Promise(resolve => readAsArrayBuffer(blob, resolve));
}
export function deepAssign(to, ...rest) {
for (let src of rest) {
for (let prop in src) {
const value = src[prop];
if (typeof value === 'object' && !Array.isArray(value)) {
to[prop] = deepAssign(to[prop] || {}, value);
} else if (value === undefined && to[prop] !== undefined) {
delete to[prop];
} else {
to[prop] = value;
}
}
}
return to;
}
export function extractID(doc) {
return doc._id;
}