mirror of
https://github.com/wekan/wekan.git
synced 2026-02-21 07:24:07 +01:00
Add local fork of meteor-reactive-cache package
- Clone @wekanteam/meteor-reactive-cache to npm-packages/ - Add .meteorignore to exclude npm-packages from Meteor - Update package.json to use local file path This allows direct modification of the package for Meteor 3.0 async migration while maintaining publishability to npm.
This commit is contained in:
parent
88b35a6415
commit
e241e27ca1
40 changed files with 10369 additions and 4 deletions
56
npm-packages/meteor-reactive-cache/src/ReactiveCache.js
Normal file
56
npm-packages/meteor-reactive-cache/src/ReactiveCache.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import Tracker from './meteor/tracker';
|
||||
|
||||
export default class ReactiveCache {
|
||||
constructor(compare, shouldStop) {
|
||||
this.shouldStop = shouldStop || (() => true);
|
||||
this.compare = compare || ((a, b) => a === b);
|
||||
this.values = {};
|
||||
this.deps = {};
|
||||
}
|
||||
|
||||
ensureDependency(key) {
|
||||
if (!this.deps[key]) this.deps[key] = new Tracker.Dependency();
|
||||
return this.deps[key];
|
||||
}
|
||||
|
||||
checkDeletion(key) {
|
||||
const dep = this.ensureDependency(key);
|
||||
if (dep.hasDependents()) return false;
|
||||
delete this.values[key];
|
||||
delete this.deps[key];
|
||||
return true;
|
||||
}
|
||||
|
||||
clear() {
|
||||
Object.keys(this.values).forEach((key) => this.del(key));
|
||||
}
|
||||
|
||||
del(key) {
|
||||
const dep = this.ensureDependency(key);
|
||||
delete this.values[key];
|
||||
if (this.checkDeletion(key)) return;
|
||||
dep.changed();
|
||||
}
|
||||
|
||||
set(key, data, bypassCompare) {
|
||||
const dep = this.ensureDependency(key);
|
||||
const current = this.values[key];
|
||||
this.values[key] = data;
|
||||
if (!this.compare(current, data) || bypassCompare) {
|
||||
dep.changed();
|
||||
}
|
||||
}
|
||||
|
||||
get(key) {
|
||||
const data = this.values[key];
|
||||
if (Tracker.currentComputation) {
|
||||
const dep = this.ensureDependency(key);
|
||||
dep.depend();
|
||||
Tracker.currentComputation.onStop(() => {
|
||||
if (!this.shouldStop(key)) return;
|
||||
this.checkDeletion(key);
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue