mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:43:19 +08:00
FIX: Prevent PreloadStore
from calling the finder when value is falsy (#14899)
This commit is contained in:
parent
79f49dfb7a
commit
97aa56bdc3
|
@ -3,10 +3,10 @@
|
|||
import { Promise } from "rsvp";
|
||||
|
||||
export default {
|
||||
data: {},
|
||||
data: new Map(),
|
||||
|
||||
store(key, value) {
|
||||
this.data[key] = value;
|
||||
this.data.set(key, value);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -16,9 +16,9 @@ export default {
|
|||
So, for example, you can't load a preloaded topic more than once.
|
||||
**/
|
||||
getAndRemove(key, finder) {
|
||||
if (this.data[key]) {
|
||||
let promise = Promise.resolve(this.data[key]);
|
||||
delete this.data[key];
|
||||
if (this.data.has(key)) {
|
||||
let promise = Promise.resolve(this.data.get(key));
|
||||
this.data.delete(key);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
@ -41,16 +41,14 @@ export default {
|
|||
},
|
||||
|
||||
get(key) {
|
||||
return this.data[key];
|
||||
return this.data.get(key);
|
||||
},
|
||||
|
||||
remove(key) {
|
||||
if (this.data[key]) {
|
||||
delete this.data[key];
|
||||
}
|
||||
this.data.delete(key);
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.data = {};
|
||||
this.data = new Map();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -54,4 +54,12 @@ module("Unit | Utility | preload-store", function (hooks) {
|
|||
const result = await PreloadStore.getAndRemove("bane");
|
||||
assert.strictEqual(result, "evil");
|
||||
});
|
||||
|
||||
test("returns falsy values without calling finder", async function (assert) {
|
||||
PreloadStore.store("falsy", false);
|
||||
const result = await PreloadStore.getAndRemove("falsy", () =>
|
||||
assert.ok(false)
|
||||
);
|
||||
assert.strictEqual(result, false);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user