Pull `Direction` values into an enum (#353)
Summary: This saves clients from having to pollute their global namespace with `IN` and `OUT` (and, soon, `ANY`). Calls now look like: ```js myNode.neighbors({direction: Direction.OUT}); ``` Callers who prefer to pollute their namespaces are of course still welcome to do so, at the cost of one `const {IN, OUT} = Direction`. Test Plan: New unit tests for frozenness included. wchargin-branch: direction-enum
This commit is contained in:
parent
4a06485a99
commit
dfaa7d9764
|
@ -14,11 +14,15 @@ export type Edge = {|
|
|||
|};
|
||||
|
||||
export type Neighbor = {|+node: NodeAddress, +edge: Edge|};
|
||||
export opaque type Direction = Symbol;
|
||||
export const IN: Direction = Symbol("IN");
|
||||
export const OUT: Direction = Symbol("OUT");
|
||||
|
||||
export opaque type DirectionT = Symbol;
|
||||
export const Direction: {|+IN: DirectionT, +OUT: DirectionT|} = Object.freeze({
|
||||
IN: Symbol("IN"),
|
||||
OUT: Symbol("OUT"),
|
||||
});
|
||||
|
||||
export type NeighborsOptions = {|
|
||||
+direction: ?Direction,
|
||||
+direction: ?DirectionT,
|
||||
+nodePrefix: ?NodeAddress,
|
||||
+edgePrefix: ?EdgeAddress,
|
||||
|};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import {Address, Graph, edgeToString} from "./graph";
|
||||
import {Address, Direction, Graph, edgeToString} from "./graph";
|
||||
import type {NodeAddress, EdgeAddress} from "./graph";
|
||||
|
||||
describe("core/graph", () => {
|
||||
|
@ -30,6 +30,15 @@ describe("core/graph", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Direction values", () => {
|
||||
it("are read-only", () => {
|
||||
expect(() => {
|
||||
// $ExpectFlowError
|
||||
Direction.IN = Direction.OUT;
|
||||
}).toThrow(/read.only property/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Graph class", () => {
|
||||
it("can be constructed", () => {
|
||||
const x = new Graph();
|
||||
|
|
Loading…
Reference in New Issue