From ee5f2a9a56741797e81cb0fe48539a9ccaa3911e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Mon, 5 Aug 2019 06:21:59 +0200 Subject: [PATCH] MapUtil.pushValue returns the array Minor change to the API for MapUtil.pushValue. Now it returns the resultant array. I've found this convenient in at least one case, and previously we weren't returning anything, so it's a cheap change. Test plan: Unit test added. --- src/util/map.js | 3 ++- src/util/map.test.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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); + }); }); });