Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Commit 759dc05

Browse files
authored
Merge pull request #172 from data-provider/fix-clean-dependencies-cache
Fix clean dependencies cache
2 parents be8f12e + 46c487b commit 759dc05

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
### Added
99
### Changed
1010
### Fixed
11+
- fix: Selector cleanDependenciesCache method was cleaning only in progress dependencies if the selector read was in progress, so previous dependencies were not being cleaned
1112
### Removed
1213

1314
## [2.9.0] - 2020-12-27

src/Selector.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ class SelectorBase extends Provider {
230230
}
231231

232232
_unthrottledCleanDependenciesCache(options = {}) {
233-
if (this._inProgressDependencies.size > 0) {
234-
this._cleanCaches(Array.from(this._inProgressDependencies), options);
235-
} else {
236-
this._cleanCaches(this._resolvedDependencies, options);
237-
}
233+
const dependenciesToClean = new Set(this._resolvedDependencies);
234+
this._inProgressDependencies.forEach((dependency) => {
235+
dependenciesToClean.add(dependency);
236+
});
237+
this._cleanCaches(Array.from(dependenciesToClean), options);
238238
}
239239

240240
// Define base tag

test/selector/cache-dependencies-clean.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,39 @@ describe("Selector when cleanDependenciesCache method is called", () => {
113113
expect(dependency3.cleanDependenciesCache.callCount).toEqual(1);
114114
});
115115

116+
it("should call to clean all dependendencies cache, even when read is in progress", async () => {
117+
let readSelectorPromise;
118+
expect.assertions(3);
119+
sandbox.spy(dependency1, "cleanDependenciesCache");
120+
sandbox.spy(dependency2, "cleanDependenciesCache");
121+
sandbox.spy(dependency3, "cleanDependenciesCache");
122+
await selector.read();
123+
dependency3.cleanCache();
124+
readSelectorPromise = selector.read();
125+
selector.cleanDependenciesCache();
126+
await readSelectorPromise;
127+
expect(dependency1.cleanDependenciesCache.callCount).toEqual(1);
128+
expect(dependency2.cleanDependenciesCache.callCount).toEqual(1);
129+
expect(dependency3.cleanDependenciesCache.callCount).toEqual(1);
130+
});
131+
132+
it("should return last data returned by all dependencies, even when read is in progress", async () => {
133+
let readSelectorPromise;
134+
expect.assertions(2);
135+
results = {
136+
dependency1: ["foo", "foo2"],
137+
dependency2: ["foo3", "foo4"],
138+
dependency3: ["foo5", "foo6"],
139+
};
140+
const result = await selector.read();
141+
expect(result).toEqual(["foo", "foo3", "foo5"]);
142+
dependency3.cleanCache();
143+
readSelectorPromise = selector.read();
144+
selector.cleanDependenciesCache();
145+
await readSelectorPromise;
146+
expect(selector.state.data).toEqual(["foo2", "foo4", "foo6"]);
147+
});
148+
116149
it("should call to clean all dependendencies cache except that in the except option", async () => {
117150
expect.assertions(3);
118151
sandbox.spy(dependency1, "cleanDependenciesCache");

0 commit comments

Comments
 (0)