@isograph/disposable-types 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @isograph/disposable-types
2
+
3
+ > A shared library that exports commonly-used types related to disposable items.
4
+
5
+ See the `@isograph/react-disposable-state` library for more information.
6
+
7
+ ## What is a disposable item?
8
+
9
+ A disposable item is anything that is either explicitly created or must be explicitly cleaned up. That is, it is an item with a lifecycle.
10
+
11
+ A disposable item is safe to use as long as its destructor has not been called.
12
+
13
+ Code that manages disposable items (such as the `useDisposableState` hook) should also ensure that each destructor is eventually called, and should not provide access to the underlying item once the destructor has been called.
14
+
15
+ Disposable items are allowed to have side effects when created or when destroyed.
16
+
17
+ ### Example
18
+
19
+ An example might be a claim to a resource in a shared store.
20
+
21
+ ```js
22
+ const [claim, disposeClaim]: ItemCleanupPair<Claim> = store.getClaimToResource({
23
+ id: 4,
24
+ });
25
+
26
+ // Because the claim has not been disposed, this is safe to do:
27
+ const data = store.lookup(claim);
28
+
29
+ disposeClaim();
30
+
31
+ // Now that we've disposed of the claim, the underlying resource might have been removed from the store, so the following is not safe:
32
+ const unsafeData = store.lookup(claim);
33
+ ```
@@ -0,0 +1,3 @@
1
+ export type CleanupFn = () => void;
2
+ export type ItemCleanupPair<T> = [T, CleanupFn];
3
+ export type Factory<T> = () => ItemCleanupPair<T>;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@isograph/disposable-types",
3
+ "version": "0.0.4",
4
+ "description": "Common types for disposable items",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "author": "Isograph Labs",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "compile": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
11
+ "compile-watch": "tsc -p tsconfig.pkg.json --watch",
12
+ "test": "echo this package has no tests",
13
+ "test-watch": "echo this package has no tests",
14
+ "coverage": "echo this package has no coverage",
15
+ "prepack": "yarn run compile"
16
+ },
17
+ "dependencies": {},
18
+ "devDependencies": {
19
+ "typescript": "^5.0.3"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type CleanupFn = () => void;
2
+ export type ItemCleanupPair<T> = [T, CleanupFn];
3
+ export type Factory<T> = () => ItemCleanupPair<T>;
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/",
5
+ "rootDir": "./src/",
6
+ "declaration": true
7
+ },
8
+ "include": ["src/**/*.ts"]
9
+ }