diff --git a/README.md b/README.md index 243ab14..fbe833a 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,65 @@ -# ssprojet +# miis -![NPM](https://img.shields.io/npm/l/ssprojet?color=blue&style=flat-square) ![npm](https://img.shields.io/npm/v/ssprojet?color=blue&style=flat-square) +![NPM](https://img.shields.io/npm/l/miis?color=blue&style=flat-square) ![npm](https://img.shields.io/npm/v/miis?color=blue&style=flat-square) -The `ssprojet` is a template to start a simple project. +> The `miis` is a tiny functional event subscriber and dispatcher. -## Features +## Install -- `pnpm` - package manager -- `vitest` - test library -- `docusaurus` - document library -- `prettier` - code style formate -- `eslint` - code quality +This project need node and npm. -## How to use +```shell +npm install miis --save +``` -You could use `degit Yukiniro/ssprojet your-project-name` to create a project. +or -If you have no `degit`. Please install it by `npm install -g degit`. +```shell +pnpm add miis --save +``` + +## Useage + +```javascript +import miis from 'miis'; + +miis.subscribe("a", (...args) => { + console.log('a event call'); // a event call + console.log(...args); /// 1, 2, 3 +}); +miis.dispatch("a", 1, 2, 3); +``` + +You could unsubscribe the event lisenter with the result of subscribe. + +```javascript +import miis from 'miis'; + +const unsubscribe = miis.subscribe("a", () => { + console.log('a event call'); +}); +unsubscribe(); + +miis.dispatch("a"); // not work +``` + +## API + +### subscirbe + +Register an event listenter for the given name. + +#### Params + +- `eventName` __string | symbol__ Name of event to listen for. +- `listenter` __Function__ Function to call in response to given event + +#### Returns + +- `unsubscribe` __Function__ Function to remove the listenter. + +### dispatch + +Invoke all handlers for the given name. + +- `eventName` __string | symbol__ Name of event to invoke for. \ No newline at end of file diff --git a/package.json b/package.json index f70c36c..85603c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "miis", - "version": "0.0.1", + "version": "1.0.0", "description": "Tiny functional event subscriber and dispatcher.", "main": "index.ts", "scripts": {