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
This commit is contained in:
William Chargin 2018-03-02 13:49:34 -08:00 committed by GitHub
parent f305a48391
commit 97446138ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -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<T> = {|
address: Address,
payload: T,
+address: Address,
+payload: T,
|};
export type Edge<T> = {|
address: Address,
src: Address,
dst: Address,
payload: T,
+address: Address,
+src: Address,
+dst: Address,
+payload: T,
|};
export class Graph {

View File

@ -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<T: {address: Address}>(xs: T[]) {
function sortedByAddress<T: {+address: Address}>(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<T: {address: Address}>(xs: T[], ys: T[]) {
function expectSameSorted<T: {+address: Address}>(xs: T[], ys: T[]) {
expect(sortedByAddress(xs)).toEqual(sortedByAddress(ys));
}