mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-17 15:06:56 +00:00
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 type Neighbor = {|+node: NodeAddress, +edge: Edge|};
|
||||||
export opaque type Direction = Symbol;
|
|
||||||
export const IN: Direction = Symbol("IN");
|
export opaque type DirectionT = Symbol;
|
||||||
export const OUT: Direction = Symbol("OUT");
|
export const Direction: {|+IN: DirectionT, +OUT: DirectionT|} = Object.freeze({
|
||||||
|
IN: Symbol("IN"),
|
||||||
|
OUT: Symbol("OUT"),
|
||||||
|
});
|
||||||
|
|
||||||
export type NeighborsOptions = {|
|
export type NeighborsOptions = {|
|
||||||
+direction: ?Direction,
|
+direction: ?DirectionT,
|
||||||
+nodePrefix: ?NodeAddress,
|
+nodePrefix: ?NodeAddress,
|
||||||
+edgePrefix: ?EdgeAddress,
|
+edgePrefix: ?EdgeAddress,
|
||||||
|};
|
|};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {Address, Graph, edgeToString} from "./graph";
|
import {Address, Direction, Graph, edgeToString} from "./graph";
|
||||||
import type {NodeAddress, EdgeAddress} from "./graph";
|
import type {NodeAddress, EdgeAddress} from "./graph";
|
||||||
|
|
||||||
describe("core/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", () => {
|
describe("Graph class", () => {
|
||||||
it("can be constructed", () => {
|
it("can be constructed", () => {
|
||||||
const x = new Graph();
|
const x = new Graph();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user