diff --git a/src/util/map.js b/src/util/map.js index 131cf00..e3457fa 100644 --- a/src/util/map.js +++ b/src/util/map.js @@ -153,10 +153,11 @@ export function merge(maps: $ReadOnlyArray>): Map { * If the key is already in the map, its value will be mutated, not * replaced. */ -export function pushValue(map: Map, key: K, value: V): void { +export function pushValue(map: Map, key: K, value: V): V[] { let arr = map.get(key); if (arr == null) { map.set(key, (arr = [])); } arr.push(value); + return arr; } diff --git a/src/util/map.test.js b/src/util/map.test.js index 213f138..adbce56 100644 --- a/src/util/map.test.js +++ b/src/util/map.test.js @@ -325,5 +325,11 @@ describe("util/map", () => { MapUtil.pushValue(map, "foo", 1); expect(map.get("foo")).toBe(arr); }); + it("returns the resultant array", () => { + const arr = []; + const map = new Map().set("foo", arr); + const result = MapUtil.pushValue(map, "foo", 1); + expect(result).toBe(arr); + }); }); });