0.4.0 ā€¢ Published 1 year ago

@dwijbavisi/genetic-pathway v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

genetic-pathway 0.4.0

šŸ‘€ Subject-observer pattern using Proxy traps

Table of Contents

Installation

This project is published on npm at @dwijbavisi/genetic-pathway

# Install via npm
npm i @dwijbavisi/genetic-pathway
// Import in your project
import { tokens, Genome } from '@dwijbavisi/genetic-pathway';

Usage

Below is the minimal example of how to use this library.

// Import in your project
import { Genome } from '@dwijbavisi/genetic-pathway';

// Host can be any eventTarget object
const host = document.createElement('div');

// All events will be dispatched on this host
const genome = new Genome(host);

// Use the genome to handle proxy traps
const gene = new Proxy({
    name: {
        first: 'Taciturn',
        last: 'Coder'
    }
}, genome);

// Add event listeners to the host
host.addEventListener(':/name/first', (e) => {
    console.log('Property: :/name/first changed');
    console.log(e);
});
host.addEventListener(':/name/last', (e) => {
    console.log('Property: :/name/last changed');
    console.log(e);
});

// Change the values of the properties
gene.name.first = 'Dwij'; // Expected output: 'Property: :/name/first changed'
gene.name.last = 'Bavisi'; // Expected output: 'Property: :/name/last changed'

Documentation

See docs for more information.

Generating Documentation

This project uses JSDoc to generate documentation. Use the following command to generate the documentation.

npm run build-docs

# OR
jsdoc -c jsdoc.config.json -d docs/

Type Definitions

This project uses TypeScript to generate type definitions. Use the following command to generate the type definitions.

npm run build-types

# OR
npx tsc

Testing

Install the dependencies using the following command.

npm i

Code Style

This project uses eslint to implement code style checks. Use the following command to run the linter.

npm run linter

# OR
eslint index.js tokens.js src/**/*.js

Unit Tests

This project uses Jest framework for unit testing. And jest-environment-jsdom is used as a mock for browser environment. Use the following command to run the tests.

npm test

# OR
cross-env NODE_OPTIONS=--experimental-vm-modules npx jest

Code Coverage

The code coverage is generated using Jest and is stored in the ./spec/coverage directory.

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago