0.1.2 • Published 2 years ago

errorsparty-resources v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

errorsparty-resources

This package lets you create a resource table of which you can add or remove resources from. The resources can be used across your project and other packages if the resource table is shared with them.

Usage

  1. Create a resource table.
const myResourceTable = new ResourceTable();
  1. Create a new resource type.
class PersonResource extends Resource {
  public constructor(public readonly name: string) {
    super();
  }

  public greet(format = "Hello, %s!") {
    console.log(format, this.name);
  }
}
  1. Add a resource to the resource table.
const rid = myResourceTable.add(new PersonResource("John"));
  1. An eternity later ... use the resource.
const resource = myResourceTable.getOrThrow(rid, PersonResource);
resource.greet();
// Hello, John!
  1. Remove the resource when it is no longer needed.
await myResourceTable.remove(rid, PersonResource);