npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-event-manager

v0.1.2

Published

allows an object to notify other objects about changes in their state

Downloads

7

Readme

react-native-event-manager

The React Native Event Manager is a utility library designed to simplify event handling and management in React Native applications. It provides a centralized event management system that allows components to communicate efficiently through events.

Installation

npm install react-native-event-manager

Usage

The ComponentA checks for changes in the 'onUpdate' state

import { useOnEvent } from 'react-native-event-manager'

function ComponentA(): JSX.Element {

  const [value, setValue] = useState(-1)
  
  useOnEvent('onUpdate', (newValue) => {
    setValue(newValue)
  })

  return(
    <Text>{value}</Text>
  )
}

The ComponentB notify a change to the 'onUpdate' state

import { notifyEvent } from 'react-native-event-manager'

function ComponentB(): JSX.Element {

  const [count, setCount] = useState(0)

  const handlePress = () => {
    notifyEvent('onUpdate', count)
    setCount(count + 1)
  }

  return(
    <Button title='Send' onPress={handlePress}/>
  )
}

EventManager Class

constructor()

Initializes the EventManager instance.

get()

Retrieves the singleton instance of the EventManager.

getListener(index: number): EventListener | undefined

Retrieves a listener at the specified index.

getListenerCount(): number

Returns the number of registered listeners.

removeAllListener(eventName: string | null): boolean

Removes all listeners for the specified event name. If eventName is null, removes all listeners.

remove(listener: EventListener): boolean

Removes the specified listener from the event manager.

sync(eventName: string): Promise<V | null>

Returns a Promise that resolves with the value of the next occurrence of the specified event.

on(eventName: string, callback: Callback): EventListener

Subscribes a listener to the specified event. Returns the created EventListener.

once(eventName: string, callback: Callback): EventListener

Subscribes a listener to the specified event, automatically removing it after the first occurrence. Returns the created EventListener.

notify(eventName: string, value?: V): void

Notifies all listeners of the specified event with an optional value.

EventListener Class

constructor(eventManager: EventManager, name: string, callback: Callback)

Initializes an EventListener instance with the specified event manager, event name, and callback function.

remove()

Removes the listener from the event manager.

update(value?: T)

Notifies all registered callbacks with an optional value.

useOnEvent Function

useOnEvent(eventName: string, callback: Callback)

A React hook for subscribing to a specific event. Automatically removes the listener on component unmount.

useOnEvents Function

useOnEvents(observers: { [key: string]: Callback; })

A React hook for subscribing to multiple events specified in the observers object. Automatically removes all listeners on component unmount.

notifyEvent Function

notifyEvent(eventName: string, value?: V): void

Notifies all listeners of the specified event with an optional value.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library