From 97446138ab6b8c926fcb29b3737e1d7295c59bcf Mon Sep 17 00:00:00 2001 From: William Chargin Date: Fri, 2 Mar 2018 13:49:34 -0800 Subject: [PATCH] Make `Address`, `Node`, `Edge` read-only and exact (#56) Summary: Again: we assume these invariants, so we may as well encode them. We should just keep in mind that non-Flow users may wantonly violate these, so we should still code defensively. wchargin-branch: readonly-exact --- src/backend/graph.js | 22 +++++++++++----------- src/backend/graph.test.js | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/backend/graph.js b/src/backend/graph.js index 0d392eb..2719114 100644 --- a/src/backend/graph.js +++ b/src/backend/graph.js @@ -1,21 +1,21 @@ // @flow -export type Address = { - repositoryName: string, - pluginName: string, - id: string, -}; +export type Address = {| + +repositoryName: string, + +pluginName: string, + +id: string, +|}; export type Node = {| - address: Address, - payload: T, + +address: Address, + +payload: T, |}; export type Edge = {| - address: Address, - src: Address, - dst: Address, - payload: T, + +address: Address, + +src: Address, + +dst: Address, + +payload: T, |}; export class Graph { diff --git a/src/backend/graph.test.js b/src/backend/graph.test.js index cc810dc..34ad801 100644 --- a/src/backend/graph.test.js +++ b/src/backend/graph.test.js @@ -9,7 +9,7 @@ describe("graph", () => { // array with undefined order. We use these functions to // canonicalize the ordering so that we can then test equality with // `expect(...).toEqual(...)`. - function sortedByAddress(xs: T[]) { + function sortedByAddress(xs: T[]) { function cmp(x1: T, x2: T) { const a1 = addressToString(x1.address); const a2 = addressToString(x2.address); @@ -17,7 +17,7 @@ describe("graph", () => { } return [...xs].sort(cmp); } - function expectSameSorted(xs: T[], ys: T[]) { + function expectSameSorted(xs: T[], ys: T[]) { expect(sortedByAddress(xs)).toEqual(sortedByAddress(ys)); }