Skip to content

Commit

Permalink
Update API.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse authored Oct 6, 2019
1 parent 43d8cf3 commit de1482f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
## Introduction

The `Topo` object is the container for topologically sorting a list of nodes with non-circular interdependencies.

## Example

```js
const Topo = require('@hapi/topo');

const morning = new Topo();

morning.add('Nap', { after: ['breakfast', 'prep'] });

morning.add([
'Make toast',
'Pour juice'
], { before: 'breakfast', group: 'prep' });

morning.add('Eat breakfast', { group: 'breakfast' });

morning.nodes; // ['Make toast', 'Pour juice', 'Eat breakfast', 'Nap']
```

## Methods

### `new Topo()`

Creates a new `Topo` object.

### `topo.add(nodes, [options])`

Specifies an additional node or list of nodes to be topologically sorted where:
- `nodes` - a mixed value or array of mixed values to be added as nodes to the topologically sorted list.
- `options` - optional sorting information about the `nodes`:
Expand All @@ -16,9 +40,11 @@ Specifies an additional node or list of nodes to be topologically sorted where:
Returns an array of the topologically sorted nodes.

### `topo.nodes`

An array of the topologically sorted nodes. This list is renewed upon each call to [`topo.add()`](#topoaddnodes-options).

### `topo.merge(others)`

Merges another `Topo` object into the current object where:
- `others` - the other object or array of objects to be merged into the current one. `null`
values are ignored.
Expand All @@ -27,4 +53,4 @@ Returns an array of the topologically sorted nodes. Will throw if a dependency e
combined items.

If the order in which items have been added to each list matters, use the `sort` option in `topo.add()` with an incrementing
value providing an absolute sort order among all items added to either object.
value providing an absolute sort order among all items added to either object.

0 comments on commit de1482f

Please sign in to comment.