0.0.9 โข Published 2 years ago
@infini-soft/lib-events v0.0.9
Getting started
Typescript Ultra Small Event (~400 bytes) Publisher/Subscribers.
โจ Features
- Event Pub/Sub
- Strongly typed
- Ultra small (~400 bytes)
- NodeJS/Browser
๐ Documentation
Get all documentations, examples and execute it directly from our website, the โ kitchen! Come cook software :) https://www.kitchen.infini-soft.com/libraries/events
๐ฆ Install
$ npm install @infini-soft/lib-events --save
# or
$ yarn add @infini-soft/lib-events
๐จ Examples
React
import React from 'react';
import { events } from '@infini-soft/lib-events';
export default () => {
const { on, fire } = events();
React.useEffect(() => {
on('test', (payload) => {
alert(payload.message);
});
}, []);
return (
<>
<h3>Fire test event</h3>
<button
onClick={() => {
fire('test', 'Hello');
}}
>
Test
</button>
</>
);
};
Node
import { events } from '@infini-soft/lib-events';
const { on, fire } = events();
on("test", console.log)
fire('test', 'Hello');
๐ Methods
Name | Type | Description |
---|---|---|
fire | <T>(event : string , message? : T , source? : string ) => void | Fires an event |
on | <T>(event : string , handler : Handler <T >) => () => void | Subscribe to event |
onAll | <T>(handler : Handler <T >) => () => void | Subscribe to all events |
๐งช Unit Tested
Powered ๐ by Infinisoft Inc. Wanna cook the future? Come in the kitchen https://www.kitchen.infini-soft.com