Skip to content

Commit

Permalink
better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Apr 11, 2024
1 parent a1e87fa commit 6334b2e
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ The "*one-stop shop*" solution for JS Proxies and FFI APIs.

**[Documentation](https://webreflection.github.io/js-proxy/)**

- - -

### Table of content

* [API](#api) that describes the default exported utility
* [jsProxy](#jsproxy) that describes the namespace returned by the utility
* [Heap](#heap) that describes what `js-proxy/heap` exports as extra utility
* **[API](#api)** that describes the default exported utility
* **[jsProxy](#jsproxy)** that describes the namespace returned by the utility
* **[Heap](#heap)** that describes what `js-proxy/heap` exports as extra utility
* **[Traps](#traps)** that describes what `js-proxy/traps` exports
* **[Types](#types)** that describes what `js-proxy/types` exports

## API

Expand All @@ -25,8 +29,7 @@ Each handler can have zero, one or more [proxy traps](https://developer.mozilla.
* **destruct** which, if present, will orchestrate automatically a [FinalizationRegistry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry) logic to invoke such trap once its proxied value is not used anymore in the wild.
* **valueOf** which, if present, allows the `valueOf(proxy)` utility to retrieve directly the underlying proxied value.

> ℹ️ **Important**
>
> [!Warning]
> If the namespace contains `object`, `array`, or `function` as own entries the value can be either a reference to those types or actually a number or any other primitive which goal is to reflect proxies across worlds (boundaries, workers, realms, interpreters).
>
> In case those references are primitives it is mandatory to define all native traps otherwise the `Reflect` methods would fail at dealing with numbers, strings, or any other kind of primitive.
Expand Down Expand Up @@ -355,3 +358,47 @@ addEventListener('message', ({ data }) => {
In the outer world, the `proxy.object({_ref: value})` could forward back via `postMessage` all traps, including the `destruct` when it happens, so that the worker can apply and reply with the result.

As summary, this export helps relating any reference to a unique identifier and it holds such reference until it's dropped. This is particularly useful to avoid the current realm collecting that reference, as it might be used solely in the outer world, still enabling, via `destruct` ability, to free memory on occasion.


## Traps

The `js-proxy/traps` exports the following:

```js
// Standard Proxy Traps
export const APPLY = 'apply';
export const CONSTRUCT = 'construct';
export const DEFINE_PROPERTY = 'defineProperty';
export const DELETE_PROPERTY = 'deleteProperty';
export const GET = 'get';
export const GET_OWN_PROPERTY_DESCRIPTOR = 'getOwnPropertyDescriptor';
export const GET_PROTOTYPE_OF = 'getPrototypeOf';
export const HAS = 'has';
export const IS_EXTENSIBLE = 'isExtensible';
export const OWN_KEYS = 'ownKeys';
export const PREVENT_EXTENSION = 'preventExtensions';
export const SET = 'set';
export const SET_PROTOTYPE_OF = 'setPrototypeOf';

// Custom (JS)Proxy Traps
export const DESTRUCT = 'destruct';
export const VALUE_OF = 'valueOf';
```


## Types

The `js-proxy/types` exports the following:

```js
export const ARRAY = 'array';
export const BIGINT = 'bigint';
export const BOOLEAN = 'boolean';
export const FUNCTION = 'function';
export const NULL = 'null';
export const NUMBER = 'number';
export const OBJECT = 'object';
export const STRING = 'string';
export const SYMBOL = 'symbol';
export const UNDEFINED = 'undefined';
```

0 comments on commit 6334b2e

Please sign in to comment.