All Projects → jnsdls → react-listener-provider

jnsdls / react-listener-provider

Licence: MIT license
Create a ReactListenerProvider and use HOC (Higher Order Components) to listen for Events in one place.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-listener-provider

Unity-EventBinder
User Interface Event decoupler
Stars: ✭ 27 (+42.11%)
Mutual labels:  event, listener
league-lazy-event
💤 Provides a LazyListener for use with League\Event which allows for lazy fetching of actual listeners.
Stars: ✭ 14 (-26.32%)
Mutual labels:  event, listener
spa-bus
🔥Tools for multilevel components to pass values in any SPA
Stars: ✭ 15 (-21.05%)
Mutual labels:  event, listener
Elegantbus
🔥🔥Android 平台,基于LivaData的EventBus,无侵入,更优雅,支持跨进程,跨应用粘性事件,自定义事件等功能。
Stars: ✭ 156 (+721.05%)
Mutual labels:  event
Libuev
Lightweight event loop library for Linux epoll() family APIs
Stars: ✭ 170 (+794.74%)
Mutual labels:  event
Juggle
juggle是一个极简的、组件式的js框架。无依赖,完美闭包,灵活且适合渐进学习,可与任何框架整合。包含(支持冒泡的事件 || Tween || MV框架 || http || websocket || 资源 || 模块)等组件,按需选择组件,不绑架开发者。
Stars: ✭ 208 (+994.74%)
Mutual labels:  event
azeroth-event
Lightweight event-driven framework
Stars: ✭ 18 (-5.26%)
Mutual labels:  event
Lapidus
Stream your PostgreSQL, MySQL or MongoDB databases anywhere, fast.
Stars: ✭ 145 (+663.16%)
Mutual labels:  event
React Native Webview Messaging
✉️ Send/Receive data between React Native app and WebView
Stars: ✭ 251 (+1221.05%)
Mutual labels:  event
Qmq
QMQ是去哪儿网内部广泛使用的消息中间件,自2012年诞生以来在去哪儿网所有业务场景中广泛的应用,包括跟交易息息相关的订单场景; 也包括报价搜索等高吞吐量场景。
Stars: ✭ 2,420 (+12636.84%)
Mutual labels:  event
October30
macOS Screen Saver showing 371 Apple logos from their 2018 iPad event
Stars: ✭ 200 (+952.63%)
Mutual labels:  event
Keybd event
For simulate key press in Linux, Windows and Mac in golang
Stars: ✭ 175 (+821.05%)
Mutual labels:  event
Unpeek Livedata
LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.
Stars: ✭ 208 (+994.74%)
Mutual labels:  event
Noel
A universal, human-centric, replayable javascript event emitter.
Stars: ✭ 158 (+731.58%)
Mutual labels:  event
Swift Utils
A collection of handy swift utils
Stars: ✭ 253 (+1231.58%)
Mutual labels:  event
Jstarcraft Core
目标是提供一个通用的Java核心编程框架,作为搭建其它框架或者项目的基础. 让相关领域的研发人员能够专注高层设计而不用关注底层实现. 涵盖了缓存,存储,编解码,资源,脚本,监控,通讯,事件,事务9个方面.
Stars: ✭ 150 (+689.47%)
Mutual labels:  event
Medium Zoom
🔎🖼 A JavaScript library for zooming images like Medium
Stars: ✭ 2,799 (+14631.58%)
Mutual labels:  event
Evmongoose
DEPRECATED. Evmongoose is an asynchronous, event(libev) based multi-protocol embedded networking library with functions including TCP, HTTP, WebSocket, MQTT and much more. It's based on mongoose and libev implementation and it's support Lua API.
Stars: ✭ 199 (+947.37%)
Mutual labels:  event
Gear Lib
Gear-Lib, C library for IOT Embedded Multimedia and Network
Stars: ✭ 2,381 (+12431.58%)
Mutual labels:  event
Dc Sdk
DC-SDK 是基于 Cesium 进行二次开发的2、3D一体 WebGis 应用框架,该框架优化了 Cesium 的使用方式和增添了一些额外功能,旨在为开发者快速构建 WebGis 应用。🌎
Stars: ✭ 206 (+984.21%)
Mutual labels:  event

react-listener-provider

Create a provider and use HOC (Higher Order Components) to listen for Events in one place.

Usage Example

react-listener-provider exports a ReactListenerProvider component as well as a withListener() wrapper function.

Components wrapped with withListener() will have an added prop listener which exposes add() and remove() methods.

add() and remove() work just like window.addEventListener() and window.removeEventListener(), they take a type <string> argument and a callback <function> argument.

import React, { Component } from 'react';
import ReactListenerProvider, { withListener } from '../../src';

class MouseMove extends Component {
  state = { x: 0, y: 0 };

  componentDidMount() {
    const { add } = this.props.listener;
    add('mousemove', ({ clientX: x, clientY: y }) => this.setState({ x, y }));
  }

  componentWillUnmount() {
    const { remove } = this.props.listener;
    remove('mousemove', ({ clientX: x, clientY: y }) => this.setState({ x, y }));
  }

  render() {
    const { x, y } = this.state;
    return (
      <div>
        <span>x: {x}</span>
        <span> - </span>
        <span>y: {y}</span>
      </div>
    );
  }
}


const WrappedComponent = withListener(MouseMove);


class App extends Component {
  render() {
    return (
      <ReactListenerProvider>
        <WrappedComponent />
      </ReactListenerProvider>
    );
  }
}

Installation

yarn add react-listener-provider

Since version 0.2.0 you'll also need "prop-types" as a peer dependency.

yarn add prop-types

API

Props

ReactListenerProvider

none

Component wrapped with withListener()

listener: React.PropTypes.shape({
      add: React.PropTypes.func.isRequired,
      remove: React.PropTypes.func.isRequired
    }).isRequired

Development

  1. clone this repo
  2. yarn
  3. cd demo
  4. yarn && yarn start

Attribution

The repo structure as well as the inspiration to create this project come from react-perimiter.

Thanks to @aweary for the encouragement.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].