Skip to content

BoomTech-LLC/Boom-JS-Emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

boom-js-emitter

NPM github github NPM


Logo

Boom JS Emitter

The Simplest and the lightest event management tool.
Report Bug · Request Feature

Getting Started

Hey and welcome. You have started the development with the Simplest and lightest event management tool

You don't need to read huge docs or watch videos for hours to start using this.

Just read a few sentences below

1. Initialization

Create a new file and name it Emitter
Import Emiiter in new Emiiter File and declare it.
Export the Emitter

Emiiter.js

import Emitter from 'boom-js-emitter'

const Emitter = new Emitter()

export default Emitter

2. Create an event

Import the Emitter you have declared wherever you want.
Create a useEffect and declare an event in it using the subscribe function

import React, { useEffect } from 'react'
import Emitter from './../Emitter' // The file you have created


const SomeComponent = () => {

  useEffect(() => {
    Emitter.subscribe("MY_EVENT_NAME", (payload) => {
      console.log("Doing something with my data", payload);
    })
  }, [])
  
  return (
    <>
      The component which I'm proud for
    </>
  )
}
export default SomeComponent

subscribe creates an event with this name if the event doesn't exist and starts listening to him

3. Remove an event

When the component is dead just call the unsubscribe function

import React, { useEffect } from 'react'
import Emitter from './../Emitter' // The file you have created


const SomeComponent = () => {

  useEffect(() => {
    Emitter.subscribe("MY_EVENT_NAME", (payload) => {
      console.log("Doing something with my data", payload);
    })
    
    return () => Emitter.unsubscribe("MY_EVENT_NAME")
  }, [])
  
  return (
    <>
      The component which I'm proud for
    </>
  )
}
export default SomeComponent

4. Trigger the event

I have nothing to say just look at the codes

import React from 'react'
import Emitter from './../Emitter' // The file you have craeted


const SomeOtherComponent = () => {
  
  const handleTriggerEvent = () => Emitter.emit("MY_EVENT_NAME", "data 1", "data 2", "and so on ...")
  
  return (
    <div onClick={handleTriggerEvent}>
      Trigger the event
    </div>
  )
}
export default SomeOtherComponent

Yeah as simple as this

This is not a code this is just a

Made in BoomTech

This is an image This is an image This is an image
Tigran Nazaryan Ararat Matinyan Sahak Sahakyan

Apache 2.0 License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published