Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async putValue(value) {
/*
Merge value into cache, and get the change tree
extraChanges = await normalizeSubscriptions()
If raw, merge extraChanges into change and call listeners with that;
Othersiwe, call listeners with values from cache
*/
if (typeof value === 'undefined') value = {};
merge(this.data, value);
// console.log(this.id, 'value', value);
const gaps = getUnknown(this.data, this.sumQuery);
let fillData;
if (gaps) {
// The change added a link to some data we don't have in the cache.
// We need to fetch it and also resubscribe.
// console.log(
// 'Change caused gaps',
// value && value.visitorsByTime && value.visitorsByTime.__page__,
// this.data &&
// this.data.visitorsByTime &&
// this.data.visitorsByTime.__page__,
// );
// console.log('SumQuery', this.sumQuery);
// console.log('Gaps', gaps);
await this.resubscribe();
try {
fillData = await this.store.get(gaps, {
async pub(change) {
if (this.earlyChange) {
merge(this.earlyChanges, change);
return;
}
const { query, options, data } = this;
// Returns early if the change does not have any overlap with the query.
// DO NOT getKnown the change to only those changes that overlap; when the
// overlapping portion includes a deletion in a range, the change set
// may contain additional items to make up.
if (!getKnown(change, linkKnown(data, query))) return;
merge(data, change);
const nextQuery = getUnknown(data, query);
if (nextQuery) {
const linked = await options.resolve(nextQuery);
merge(data, linked);
if (!options.values) merge(change, linked);
}
this.data = getKnown(data, query);
this.push(options.values ? graft(this.data, query) || {} : change);
}
}
async pub(change) {
if (this.earlyChange) {
merge(this.earlyChange, change);
return;
}
const { query, options, data } = this;
// Returns early if the change does not have any overlap with the query.
// DO NOT getKnown the change to only those changes that overlap; when the
// overlapping portion includes a deletion in a range, the change set
// may contain additional items to make up.
if (!getKnown(change, linkKnown(data, query))) return;
merge(data, change);
const nextQuery = getUnknown(data, query);
if (nextQuery) {
const linked = await options.resolve(nextQuery);
merge(data, linked);
if (!options.values) merge(change, linked);
}
this.data = getKnown(data, query);
this.push(options.values ? graft(this.data, query) || {} : change);
}
}
const pub = async change => {
if (earlyChange) {
merge(earlyChange, change);
return;
}
// Returns early if the change does not have any overlap with the query.
// DO NOT getKnown the change to only those changes that overlap; when the
// overlapping portion includes a deletion in a range, the change set
// may contain additional items to make up.
if (!getKnown(change, linkKnown(data, query))) return;
merge(data, change);
const nextQuery = getUnknown(data, query);
if (nextQuery) {
const linked = await options.resolve(nextQuery);
merge(data, linked);
if (!options.values) merge(change, linked);
}
data = getKnown(data, query);
push(options.values ? graft(data, query) || {} : change);
};
pubs[id] = async change => {
if (earlyChange) {
merge(earlyChange, change);
return;
}
// Returns early if the change does not have any overlap with the query.
// DO NOT getKnown the change to only those changes that overlap; when the
// overlapping portion includes a deletion in a range, the change set
// may contain additional items to make up.
if (!getKnown(change, linkKnown(data, query))) return;
merge(data, change);
const nextQuery = getUnknown(data, query);
if (nextQuery) {
const linked = await store.get(nextQuery, options);
merge(data, linked);
if (!options.values) merge(change, linked);
}
data = getKnown(data, query);
push(options.values ? graft(data, query) || {} : change);
};
getUnknown(query) {
return getUnknown(this.data, query);
}