world-trigger
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

World Trigger

This is use for Reactjs, React-Native, Vuejs, and any js framework out there, to trigger or dispatch registered callbacks on any component without using any context.


installation

npm i world-trigger

or

yarn add world-trigger

How to use


imports

import worldTrigger from "world-trigger"

Basic Usage

import worldTrigger from "world-trigger"

const handleTestTrigger = (data) => {
  console.log(`Yey! ${data.firstname} has trigger me.`)
}
// registered the trigger
worldTrigger.addTrigger('test.trigger', handleTestTrigger)

// unregistered the trigger
worldTrigger.removeTrigger('test.trigger', handleTestTrigger)

// dispatching the trigger with data
worldTrigger.dispatchTrigger('test.trigger', { firstname: 'JR' })



Reactjs

import React from "react"
import worldTrigger from "world-trigger"

export const App = () => {
    useEffect(() => {
      const handleTestTrigger = (data) => {
        console.log(`Yey! ${data.firstname} has trigger me.`)
      }

      worldTrigger.addTrigger('test.trigger', handleTestTrigger)

      return () => worldTrigger.removeTrigger('test.trigger', handleTestTrigger)
    }, [])
    
    return ( 
        <ButtonTrigger />
    );
}

const ButtonTrigger = () => { 
    const handleClick = () => {
      worldTrigger.dispatchTrigger('test.trigger', { firstname: 'JR' })
    }

    return (
        <button type="button" onClick={handleClick}>Trigger Me</button>
    );
}

License

MIT Licensed. Copyright (c) Mytabworks 2020.

Package Sidebar

Install

npm i world-trigger

Weekly Downloads

47

Version

1.1.1

License

MIT

Unpacked Size

6.68 kB

Total Files

6

Last publish

Collaborators

  • mytabworks