Skip to content

Commit

Permalink
docs: update package identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
exbotanical committed Dec 25, 2021
1 parent 690edaf commit dacd0de
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 49 deletions.
66 changes: 50 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# effect
# resonant

[![Coverage Status](https://coveralls.io/repos/github/MatthewZito/effect/badge.svg?branch=master)](https://coveralls.io/github/MatthewZito/effect?branch=master)
[![Continuous Deployment](https://github.com/MatthewZito/effect/actions/workflows/cd.yml/badge.svg)](https://github.com/MatthewZito/effect/actions/workflows/cd.yml)
[![Continuous Integration](https://github.com/MatthewZito/effect/actions/workflows/ci.yml/badge.svg)](https://github.com/MatthewZito/effect/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/effect.svg)](https://badge.fury.io/js/effect)
[![Coverage Status](https://coveralls.io/repos/github/MatthewZito/resonant/badge.svg?branch=master)](https://coveralls.io/github/MatthewZito/resonant?branch=master)
[![Continuous Deployment](https://github.com/MatthewZito/resonant/actions/workflows/cd.yml/badge.svg)](https://github.com/MatthewZito/resonant/actions/workflows/cd.yml)
[![Continuous Integration](https://github.com/MatthewZito/resonant/actions/workflows/ci.yml/badge.svg)](https://github.com/MatthewZito/resonant/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/resonant.svg)](https://badge.fury.io/js/resonant)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Reactive effects with automatic dependency management, caching, and leak-free finalization.

## Table of Contents

- [Install](#install)
Expand All @@ -16,31 +18,63 @@
## <a name="install"></a> Installation

```bash
npm install effect
```

OR

```bash
yarn add effect
npm install resonant
```

### <a name="support"></a> Supported Environments

`effect` currently supports UMD, CommonJS (node versions >= 10), and ESM build-targets
`resonant` currently supports UMD, CommonJS (node versions >= 10), and ESM build-targets

Commonjs:

```js
const { isDefined } = require('effect');
const { resonant, effect } = require('resonant');
```

ESM:

```js
import { isDefined } from 'effect';
import { resonant, effect } from 'resonant';
```

## <a name="docs"></a> Documentation

Full documentation can be found [here](https://matthewzito.github.io/effect/effect.html)
Inspired by React's `useEffect` and Vue's `watchEffect`, `resonant` is a compact utility library that mitigates the inherent burdens of managing observable data, including dependency tracking; caching and cache invalidation; and object dereferencing and finalization.

To create an effect, you must first make the target object reactive with the `resonant` function:

```ts
import { resonant } from 'resonant';

const plainObject = {
x: 1,
y: 1
};

const r = resonant(plainObject);
```

Now, `r` is equipped with deep reactivity. All get / set operations will trigger any dependencies (i.e. effects) that happen to be observing the data.

Let's create an effect:

```ts
import { resonant, effect } from 'resonant';

const plainObject = {
x: 1,
y: 1
};

const r = resonant(plainObject);

let count = 0;

effect(() => {
count += r.x + r.y;
});
```

The effect will run immediately. It has now been cached and will execute whenever its properties change. `resonant` also uses weak references; deleted properties to which there are no references will be finalized so they may be garbage collected, as will all of that property's dependencies and effects.

Full documentation can be found [here](https://matthewzito.github.io/resonant/resonant.html)
24 changes: 12 additions & 12 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { reactive, effect } from '../src';
import { resonant, effect } from '../src';

import { forMocks } from './util';
import { forMocks } from './utils';

const r = reactive({
const r = resonant({
a: 1,
b: 2,
c: 3
Expand All @@ -22,7 +22,7 @@ describe('run effect', () => {
expect(mock).toHaveBeenCalledTimes(1);
});

it('reruns the effect when a reactive property dependency has been mutated', () => {
it('reruns the effect when a resonant property dependency has been mutated', () => {
const mock = jest.fn(() => {
r.a;
});
Expand All @@ -34,7 +34,7 @@ describe('run effect', () => {
expect(mock).toHaveBeenCalledTimes(2);
});

it('only runs effects which depend on a reactive property', () => {
it('only runs effects which depend on a resonant property', () => {
const mock = jest.fn(() => {});
const mock2 = jest.fn(() => {
r.a;
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('run effect', () => {
});

it('triggers effects on nested object mutations', () => {
const r2 = reactive({
const r2 = resonant({
a: 1,
b: {
x: {
Expand All @@ -109,7 +109,7 @@ describe('run effect', () => {
});

it('tracks and runs multiple effects', () => {
const r1 = reactive({
const r1 = resonant({
x: 1,
y: 2,
z: {
Expand All @@ -118,7 +118,7 @@ describe('run effect', () => {
}
});

const r2 = reactive({
const r2 = resonant({
c: 3,
d: 4
});
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('run effect', () => {
const mock1 = jest.fn();
const mock2 = jest.fn();

const r = reactive({
const r = resonant({
price: 1,
quantity: 2,
meta: {
Expand Down Expand Up @@ -243,10 +243,10 @@ describe('run effect', () => {
expect(total).toBe(19);
});

it('handles nested reactive properties', () => {
it('handles nested resonant properties', () => {
const mocks = Array.from({ length: 10 }, jest.fn);

const r = reactive({
const r = resonant({
a: false,
x: {
y: {
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('run effect', () => {
const mock = jest.fn();
const mock2 = jest.fn();

const r = reactive({
const r = resonant({
x: 1,
y: 1
});
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md)

## API Reference

## Packages

| Package | Description |
| --- | --- |
| [resonant](./resonant.md) | |

24 changes: 24 additions & 0 deletions docs/resonant.effect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [resonant](./resonant.md) &gt; [effect](./resonant.effect.md)

## effect() function

Create a resonant effect. All get / set operations within the handler will be tracked. An effect is run upon initialization, and subsequent to any mutations to its dependencies.

<b>Signature:</b>

```typescript
export declare function effect(handler: () => void): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| handler | () =&gt; void | |

<b>Returns:</b>

void

19 changes: 19 additions & 0 deletions docs/resonant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [resonant](./resonant.md)

## resonant package

## Functions

| Function | Description |
| --- | --- |
| [effect(handler)](./resonant.effect.md) | Create a resonant effect. All get / set operations within the handler will be tracked. An effect is run upon initialization, and subsequent to any mutations to its dependencies. |
| [resonant(target)](./resonant.resonant.md) | Make an object resonant. All object properties will be eligible dependencies for an effect. |

## Variables

| Variable | Description |
| --- | --- |
| [revokes](./resonant.revokes.md) | A map of revoke handlers. Pass in a proxy reference to retrieve its corresponding handler. |

24 changes: 24 additions & 0 deletions docs/resonant.resonant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [resonant](./resonant.md) &gt; [resonant](./resonant.resonant.md)

## resonant() function

Make an object resonant. All object properties will be eligible dependencies for an effect.

<b>Signature:</b>

```typescript
export declare function resonant<T extends Record<any, any>>(target: T): T;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| target | T | |

<b>Returns:</b>

T

13 changes: 13 additions & 0 deletions docs/resonant.revokes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [resonant](./resonant.md) &gt; [revokes](./resonant.revokes.md)

## revokes variable

A map of revoke handlers. Pass in a proxy reference to retrieve its corresponding handler.

<b>Signature:</b>

```typescript
revokes: WeakMap<Record<any, any>, IRevokeHandler>
```
20 changes: 20 additions & 0 deletions etc/resonant.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## API Report File for "resonant"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

// @public
export function effect(handler: () => void): void;

// @public
export function resonant<T extends Record<any, any>>(target: T): T;

// Warning: (ae-forgotten-export) The symbol "IRevokeHandler" needs to be exported by the entry point index.d.ts
//
// @public
export const revokes: WeakMap<Record<any, any>, IRevokeHandler>;

// (No @packageDocumentation comment for this package)

```
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "effect",
"name": "resonant",
"version": "0.0.0-development",
"description": "",
"keywords": [],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/MatthewZito/effect.git"
"url": "https://github.com/MatthewZito/resonant.git"
},
"author": "Matthew T Zito (goldmund)",
"files": [
"dist/"
],
"exports": {
"require": "./dist/effect.cjs.js",
"import": "./dist/effect.es.js"
"require": "./dist/resonant.cjs.js",
"import": "./dist/resonant.es.js"
},
"main": "./dist/effect.cjs.js",
"browser": "./dist/effect.umd.js",
"module": "./dist/effect.es.js",
"main": "./dist/resonant.cjs.js",
"browser": "./dist/resonant.umd.js",
"module": "./dist/resonant.es.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">= 10"
Expand Down Expand Up @@ -47,9 +47,9 @@
]
},
"bugs": {
"url": "https://github.com/MatthewZito/effect/issues"
"url": "https://github.com/MatthewZito/resonant/issues"
},
"homepage": "https://github.com/MatthewZito/effect#readme",
"homepage": "https://github.com/MatthewZito/resonant#readme",
"devDependencies": {
"@babel/cli": "7.15.7",
"@babel/core": "7.15.8",
Expand All @@ -62,7 +62,7 @@
"@microsoft/api-extractor": "^7.10.4",
"@rollup/plugin-babel": "5.3.0",
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-node-resolve": "13.0.6",
"@rollup/plugin-node-resolve": "13.1.1",
"@rollup/plugin-typescript": "8.3.0",
"@types/jest": "27.0.2",
"cz-conventional-changelog": "^3.3.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dacd0de

Please sign in to comment.