@live-change/dao
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -9,2 +9,3 @@ const debug = require('debug')('reactive-dao:cache') | ||
this.cache = new Map() | ||
this.extendedCache = new Map() | ||
this.mode = mode | ||
@@ -20,3 +21,3 @@ this.observables = new Map() | ||
for(const { what, data } of value) { | ||
this.cache.set(JSON.stringify(what), data) | ||
this.extendedCache.set(JSON.stringify(what), data) | ||
} | ||
@@ -48,3 +49,8 @@ } | ||
this.observables.set(cacheKey, observable) | ||
if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey)) | ||
if(this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey)) | ||
if(this.extendedCache.has(cacheKey)) { | ||
observable.restore(this.extendedCache.get(cacheKey)) | ||
return observable | ||
// do not save extended values | ||
} | ||
if(observable.isInitialized && observable.isInitialized()) { | ||
@@ -57,3 +63,4 @@ if(this.mode == 'save') { | ||
if(this.mode == 'load') { | ||
//if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey)) | ||
// if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey)) | ||
// it was loaded earlier | ||
} | ||
@@ -66,3 +73,3 @@ return observable | ||
debug("GET", cacheKey) | ||
if (this.cache.has(cacheKey)) { | ||
if(this.cache.has(cacheKey)) { | ||
const value = this.cache.get(cacheKey) | ||
@@ -72,2 +79,7 @@ debug("GET FROM CACHE", cacheKey, " => ", value) | ||
} | ||
if(this.extendedCache.has(cacheKey)) { | ||
const value = this.extendedCache.get(cacheKey) | ||
debug("GET FROM EXTENDED CACHE", cacheKey, " => ", value) | ||
return Promise.resolve(value) | ||
} | ||
if(this.mode == 'load') { | ||
@@ -81,9 +93,26 @@ } | ||
if(observable) { | ||
if(typeof observable == 'function') return observable('set', result) | ||
if(observable.notify) { | ||
return observable.notify('set', result) | ||
if(typeof observable == 'function') { | ||
observable('set', result) | ||
} else if(observable.notify) { | ||
observable.notify('set', result) | ||
} else { | ||
observable.set(result) | ||
} | ||
observable.set(result) | ||
} | ||
this.cache.set(cacheKey, result) | ||
if(what.paths) { | ||
for(const { what, data } of result) { | ||
let observable = this.observables.get(cacheKey) | ||
if(observable) { | ||
if(typeof observable == 'function') { | ||
observable('set', data) | ||
} else if(observable.notify) { | ||
observable.notify('set', data) | ||
} else { | ||
observable.set(data) | ||
} | ||
} | ||
this.extendedCache.set(JSON.stringify(what), data) | ||
} | ||
} | ||
}) | ||
@@ -90,0 +119,0 @@ } |
@@ -39,3 +39,3 @@ { | ||
}, | ||
"version": "0.3.6" | ||
"version": "0.3.7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160463
4657