@afaanbilal/pulse
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Pulse

NPM Minified Size Minified + GZipped

Author: Afaan Bilal

Introduction

Pulse is a JavaScript library for building reactive stuff.

Installation

npm i @afaanbilal/pulse

Example usage

import { createMonitor, createPulse } from "@afaanbilal/pulse";

const [count, setCount] = createPulse(0);

const h1 = document.createElement("h1");
createMonitor(() => h1.innerText = `Count is ${count()}`);

const btn = document.createElement("button");
createMonitor(() => btn.innerText = `Increment (To: ${count() + 1})`);
btn.onclick = () => setCount(count() + 1);

const btnDouble = document.createElement("button");
createMonitor(() => btnDouble.innerText = `Double (To: ${count() * 2})`);
btnDouble.onclick = () => setCount(count() * 2);

document.body.append(h1, btn, btnDouble);

Testing

npm test
> @afaanbilal/pulse@0.0.3 test
> jest --coverage

 PASS  test/index.test.ts
  √ should create a pulse (1 ms)
  √ should update a pulse
  √ should create a monitor

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |
 index.ts |     100 |      100 |     100 |     100 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.56 s, estimated 1 s
Ran all test suites.

Contributing

All contributions are welcome. Please create an issue first for any feature request or bug. Then fork the repository, create a branch and make any changes to fix the bug or add the feature and create a pull request. That's it! Thanks!

License

Pulse is released under the MIT License. Check out the full license here.

Readme

Keywords

Package Sidebar

Install

npm i @afaanbilal/pulse

Weekly Downloads

4

Version

0.0.4

License

MIT

Unpacked Size

27.7 kB

Total Files

10

Last publish

Collaborators

  • afaanbilal