Skip to content

Commit

Permalink
docs: parent envs
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Jan 17, 2024
1 parent a78c88e commit 3345b33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .changeset/slow-emus-sit.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ import env from '@zazuko/env';
import Environment from '@zazuko/env/Environment.js';
import MyFactory from './my-factory.js';

const myEnv = Environment([MyFactory], env);
const myEnv = new Environment([MyFactory], { parent: env });
```
28 changes: 15 additions & 13 deletions packages/env/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zazuko's [RDF/JS Environment](https://github.com/rdfjs-base/environment)

Like `rdf-ext`, with the addition of `@tpluscode/rdf-ns-builders`
Like `rdf-ext`, with some additional features.

```js
import env from '@zazuko/env'
Expand All @@ -16,18 +16,6 @@ const sheldonCooper = env.clownface()
.addOut(env.ns.schema.knows, tbbt.leonard)
```

Also, provides TypeScript types for the default environment and a mapped type,
which helps declare derived environment type, which combines existing envirnment
with additional factories

```ts
import { create, DefaultEnv, DerivedEnvironment } from '@zazuko/env'

class MyFactory {}

const myEnv: DerivedEnvironment<MyFactory> = create(MyFactory)
```

## Additional features

### Dataset
Expand All @@ -53,3 +41,17 @@ const dataset = rdf.dataset()

const turtle = await dataset.serialize({ format: 'text/turtle' })
```

#### Extending environments

This package adds the ability to create environments on top of existing ones. To do that, pass the parent environment to the constructor options.

```js
import env from '@zazuko/env';
import Environment from '@zazuko/env/Environment.js';
import MyFactory from './my-factory.js';

const myEnv = new Environment([MyFactory], { parent: env });
```

The `myEnv` will have all the factories from `env` and `MyFactory`.

0 comments on commit 3345b33

Please sign in to comment.