mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 12:03:38 +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";
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: {},
|
data: new Map(),
|
||||||
|
|
||||||
store(key, value) {
|
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.
|
So, for example, you can't load a preloaded topic more than once.
|
||||||
**/
|
**/
|
||||||
getAndRemove(key, finder) {
|
getAndRemove(key, finder) {
|
||||||
if (this.data[key]) {
|
if (this.data.has(key)) {
|
||||||
let promise = Promise.resolve(this.data[key]);
|
let promise = Promise.resolve(this.data.get(key));
|
||||||
delete this.data[key];
|
this.data.delete(key);
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,16 +41,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
get(key) {
|
get(key) {
|
||||||
return this.data[key];
|
return this.data.get(key);
|
||||||
},
|
},
|
||||||
|
|
||||||
remove(key) {
|
remove(key) {
|
||||||
if (this.data[key]) {
|
this.data.delete(key);
|
||||||
delete this.data[key];
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.data = {};
|
this.data = new Map();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,4 +54,12 @@ module("Unit | Utility | preload-store", function (hooks) {
|
||||||
const result = await PreloadStore.getAndRemove("bane");
|
const result = await PreloadStore.getAndRemove("bane");
|
||||||
assert.strictEqual(result, "evil");
|
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