0.0.13 โข Published 2 years ago
@infini-soft/lib-hub v0.0.13
Getting started
Typescript Ultra Small Event Hub.
โจ Features
- Event Pub/Sub
- Strongly typed
- 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/hub
๐ฆ Install
$ npm install @infini-soft/lib-hub --save
# or
$ yarn add @infini-soft/lib-hub
๐จ Examples
React
import React from 'react';
import { hub, consoleplugin } from '@infini-soft/lib-hub';
const { subscribe, error, info } = hub();
subscribe(consoleplugin);
export default () => {
return (
<>
<h3>Error in console</h3>
<button
onClick={() => {
error('Example error in console');
}}
>
Test
</button>
<button
onClick={() => {
error(
{ description: 'Example error in console with formatted output', format: true },
'Example',
);
}}
>
Format
</button>
<button
onClick={() => {
error(
{
description: 'Example error in console with verbose context',
format: true,
verbose: true,
context: { prop: 'im a context props' },
},
'Example',
);
}}
>
Format
</button>
<h3>Info in console</h3>
<button
onClick={() => {
info('Example info in console');
}}
>
Test
</button>
<button
onClick={() => {
info(
{ description: 'Example info in console with formatted output', format: true },
'Example',
);
}}
>
Format
</button>
<button
onClick={() => {
info(
{
description: 'Example info in console with verbose context',
format: true,
verbose: true,
context: { prop: 'im a context props' },
},
'Example',
);
}}
>
Format
</button>
</>
);
};
๐ Methods
Name | Type |
---|---|
debug | (description : string , source? : string ) => void <T>(payload : T , source? : string ) => void <T>(payload : T , source? : string ) => void |
emit | <T>(event : string , message? : T , source? : string ) => void |
error | (description : string , source? : string ) => void <T>(payload : T , source? : string ) => void <T>(payload : T , source? : string ) => void |
info | (description : string , source? : string ) => void <T>(payload : T , source? : string ) => void <T>(payload : T , source? : string ) => void |
on | <T>(event : string , handler : Handler <ExecutionPayload <T >>) => () => void |
subscribe | <T>(handler : Handler <ExecutionPayload <T >>) => () => void |
success | (description : string , source? : string ) => void <T>(payload : T , source? : string ) => void <T>(payload : T , source? : string ) => void |
warn | (description : string , source? : string ) => void <T>(payload : T , source? : string ) => void <T>(payload : T , source? : string ) => void |
๐งช Unit Tested
Powered ๐ by Infinisoft Inc. Wanna cook the future? Come in the kitchen https://www.kitchen.infini-soft.com