https://github.com/tokenchingy/panoptes
A simple array and object watcher function for Deno. Written in TypeScript.
https://github.com/tokenchingy/panoptes
deno javascript proxy typescript watcher
Last synced: 10 months ago
JSON representation
A simple array and object watcher function for Deno. Written in TypeScript.
- Host: GitHub
- URL: https://github.com/tokenchingy/panoptes
- Owner: TokenChingy
- License: mit
- Created: 2019-03-06T17:17:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-08T07:46:48.000Z (over 5 years ago)
- Last Synced: 2025-06-26T01:02:03.023Z (10 months ago)
- Topics: deno, javascript, proxy, typescript, watcher
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Panoptes
> A simple array and object watcher function for Deno.
[](https://denolib.com)
[](https://travis-ci.com/TokenChingy/panoptes)
## Table of Contents
- [Panoptes](#panoptes)
- [Table of Contents](#table-of-contents)
- [Usage](#usage)
- [API](#api)
- [`watch()`](#watch)
- [`object: Object`](#object-object)
- [`callback: Function`](#callback-functionvoid)
- [`options?: Object`](#options-object)
- [`callbackOnGet`](#callbackonget)
## Usage
```ts
import { watch } from 'https://deno.land/x/panoptes/mod.ts';
```
A simple example of how to use Panoptes's `watch()`.
```ts
import { watch } from 'https://deno.land/x/panoptes/mod.ts';
// Example interface for the base object.
interface BaseObjectStruct {
a: String;
b: {
c: Array;
};
e: Number;
}
// The base object that will be watched.
const baseObject: BaseObjectStruct = {
a: 'a',
b: {
c: ['d'],
},
e: 1,
};
// The new reference object that is being watched.
const watchedObject: any = watch(
baseObject,
() => {
console.log('Something happened!');
},
{
callbackOnGet: false,
},
);
// The watch callback should fire for each execution below.
watchedObject.a = 'b';
watchedObject.b.c.push('e'); // Array methods will fire the callback multiple times.
delete watchedObject.e;
//> Something happened!
//> Something happened!
//> Something happened!
//> Something happened!
```
## API
### `watch()`
```ts
watch(object: Object, callback: Function, options?: OptionsStruct);
```
#### `object: Object`
The base object in which you would like watched.
#### `callback: Function`
The callback that will be fired on change. Function should not return.
#### `options?: Object`
The options object passed into the `watch()` function. This is optional and implements the interface `OptionsStruct`.
```ts
interface OptionsStruct {
callbackOnGet: Boolean;
}
```
##### `callbackOnGet`
Setting this to `true` will enable the watcher to fire the callback function on get operations. Not setting it will disable this feature.