Add `DelegateNodeReference` to `graph` module (#307)

Also, rename `NodeDelegateReference` to `DelegateNodeReference` in the
design doc.

Test plan:
Didn't add tests, as the implementation is trivial. Flow passes.
This commit is contained in:
Dandelion Mané 2018-05-28 13:08:01 -07:00 committed by GitHub
parent 7078125c56
commit 630a6d6532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -191,10 +191,10 @@ convenient implementation detail.
Clients wont directly use `IndexedNodeReference`, though; this will be
a non-exported class of the `core/graph.js` module. Instead, they will
provide a semantic extension of `NodeDelegateReference`:
provide a semantic extension of `DelegateNodeReference`:
```javascript
class NodeDelegateReference implements NodeReference {
class DelegateNodeReference implements NodeReference {
_base: NodeReference;
constructor(base: NodeReference) {
this._base = base;
@ -208,14 +208,14 @@ class NodeDelegateReference implements NodeReference {
}
```
(Note: `NodeDelegateReference` should actually have `_base` as a
(Note: `DelegateNodeReference` should actually have `_base` as a
`Symbol`, but doing so requires Flow-appeasing hackery that I dont want
to include in this high-level overview.)
By extending this class, plugins gain great power:
```javascript
class GithubNodeReference extends NodeDelegateReference {
class GithubNodeReference extends DelegateNodeReference {
constructor(base: NodeReference) {
super(base);
const address = base.address();

View File

@ -167,3 +167,23 @@ export class Graph {
}
export type GraphJSON = any;
export class DelegateNodeReference implements NodeReference {
// TODO(@wchargin): Use a Symbol here.
__DelegateNodeReference_base: NodeReference;
constructor(base: NodeReference) {
this.__DelegateNodeReference_base = base;
}
graph() {
return this.__DelegateNodeReference_base.graph();
}
address() {
return this.__DelegateNodeReference_base.address();
}
get() {
return this.__DelegateNodeReference_base.get();
}
neighbors(options?: NeighborsOptions) {
return this.__DelegateNodeReference_base.neighbors(options);
}
}