@apollo/client#makeVar TypeScript Examples
The following examples show how to use
@apollo/client#makeVar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveVarsCache.ts From apollo-cache-policies with Apache License 2.0 | 6 votes |
registerCachedVar<T>(id: string, defaultValue: T): ReactiveVar<T> {
const cachedValue = this.readCachedVar<T>(id);
const rv = makeVar<T>(cachedValue ?? defaultValue);
if (this.registeredVars[id]) {
console.warn(`Duplicate cached reactive variable with ID ${id} detected. Multiple cached reactive variables should not share the same ID.`);
}
this.registeredVars[id] = {
rv,
defaultValue,
}
// If the cache did not already had a value for the CachedReactiveVar with this ID,
// then it should be seeded with one using the provided default value.
if (!cachedValue) {
this.writeCachedVar(id, defaultValue);
}
this.watchReactiveVar(id, rv);
return rv;
}