boom-js-emitter
v1.1.0
Published
Create custom events on your own. Emit them wherever you want
Downloads
44
Maintainers
Readme
boom-js-emitter
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
| | -- | -- | -- Tigran Nazaryan | Ararat Matinyan | Sahak Sahakyan