Project Details
Pulse
Author: Afaan Bilal
Introduction
Pulse is a JavaScript library for building reactive stuff.
Demo
A very minimal demo can be found here with the associated source code here.
A slightly less minimal demo can be found here with the associated source code here.
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);
Creating a new project
- Create a new Vite project by (choose Vanilla with/without Typescript):
npm create vite@latest
- Install Pulse
npm i @afaanbilal/pulse
Follow the example usage above.
Start
npm run dev
Testing
npm test
> @afaanbilal/[email protected] 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.
License
MIT License
Copyright (c) 2023 Afaan Bilal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.