在python中对nodejs eventemitter的一个小的重写

node-events的Python项目详细描述


node_events.py

A minor rewrite of the NodeJS EventEmitter in Python

PyPI VersionLicensePython Version

安装

通过PyPI

pip install node_events

用法

fromnode_eventsimportEventEmittermyEmitter=EventEmitter()deffn():print("An event occurred")myEmitter.on('event',fn)myEmitter.emit('event')# Prints#   An event occurred

API

Class: ^{}

The ^{} class is defined and exposed publicly by the module:

^{pr 3}$

EventEmitter.^{}(eventName, listener)

^{}

的别名

调用时发出'addlistener:{eventName}'事件。

EventEmitter.^{}(eventName, listener)

listener附加到名为eventName的事件的侦听器数组。传递eventname和listener相同组合的多个调用将导致多次添加和调用侦听器。

调用时发出'addlistener:{eventName}'事件。

默认情况下,事件侦听器按添加顺序调用。可以使用^{}方法将事件侦听器添加到侦听器数组的开头。

返回对EventEmitter的引用,以便可以链接调用。

emitter=EventEmitter()defappendListener():print('a')defprependListener():print('b')emitter.on('test',appendListener)emitter.prependListener('test',appendListener)emitter.emit('test')# Prints#   b#   a

EventEmitter.^{}(eventName, listener)

为名为eventName的事件添加一次性listener函数。下次触发eventName时,将删除此侦听器,然后调用它。

调用时发出'addlistener:{eventName}'事件。

默认情况下,事件侦听器按添加顺序调用。可以使用^{}方法将事件侦听器添加到侦听器数组的开头。

返回对EventEmitter的引用,以便可以链接调用。

emitter=EventEmitter()defappendListener():print('a')defprependListener():print('b')emitter.once('test',appendListener)emitter.prependOnceListener('test',appendListener)emitter.emit('test')# Prints#   b#   a

EventEmitter.^{}(eventName, listener)

listener函数添加到名为eventName的事件的侦听器数组的开头。传递eventname和listener相同组合的多个调用将导致多次添加和调用侦听器。

调用时发出'addlistener:{eventName}'事件。

emitter=EventEmitter()defnewConnection():print('someone connected!')emitter.prependListener('connection',newConnection)emitter.emit('connection')

返回对EventEmitter的引用,以便可以链接调用。

EventEmitter.^{}(eventName, listener)

将名为eventName的事件的一次性listener函数添加到侦听器数组的开头。下次触发eventName时,将删除此侦听器,然后调用它。

调用时发出'addlistener:{eventName}'事件。

emitter=EventEmitter()defnewConnection():print('someone connected!')emitter.prependOnceListener('connection',newConnection)emitter.emit('connection')

返回对EventEmitter的引用,以便可以链接调用。

EventEmitter.^{}([eventName])

删除所有侦听器或指定的eventName侦听器。

调用时发出'rmlistener:{eventName}'事件。

返回对EventEmitter的引用,以便可以链接调用。

EventEmitter.^{}(eventName, listener)

从名为eventName的事件的侦听器数组中删除指定的listener

调用时发出'rmlistener:{eventName}'事件。

EventEmitter.^{}(eventName, raiseException)

检查事件发射器本身是否有一个名为eventName的事件,为该操作返回一个布尔值。 如果raiseException为真,则在检查结果计算为False时引发异常。

EventEmitter.^{}(eventName)

安全地检查核心EventListenerStack是否至少有一个侦听器。 内在地实现^{}

Class: ^{}(listener)

This class wraps the ^{} function with useful, sandboxed manipulative features

The ^{} class is defined and exposed publicly by the module:

^{pr 8}$

EventListener.^{}(getter)

Number of times the function has been called

EventListener.^{}(*data)

Send the ^{} arguments to the encapsulated function in evaluation

EventListener.^{}(fn)

Check if ^{} matches with the encapsulated function Useful in finding the instance amongst others by matching its core

Class: ^{}(eventName)

Stacking layer of listeners for an event defined named ^{} Serves as an interfacing remote for series of grouped listeners

The ^{} class is defined and exposed publicly by the module:

^{pr 9}$

EventListenerStack.^{}(getter)

Return a copy of the private listeners array.

EventListenerStack.^{}(getter)

Return the number of listeners exist and are actively waiting for event firings

EventListenerStack.^{}(*data)

Send the ^{} arguments to all the listeners within the stack in the order of which they appear Returns True if the stack has any active listeners who read the data else False

EventListenerStack.^{}(fn)

Check if the stack has the listener ^{}

EventListenerStack.^{}(fn, index)

Attach the ^{} listener to the event stack. The ^{} parameter determines the index at which to place the function in the stack array Note, function calls are based on orderly calls from the stack array

EventListenerStack.^{}(fn)

Detach the ^{} listener from the stack if it exists returning True otherwise return False

EventListenerStack.^{}()

Detach all the listeners within the stack

EventListenerStack.^{}()

Check if the stack has any listeners within

EventListenerStack.^{}(fn)

Extract the ^{}实例封装了^ {CD70>}侦听器,如果它存在,否则返回^ {CD98}} /P>

开发

建筑

可以随意克隆,可以附加到license中使用,也可以发送拉取请求

git clone https://github.com/miraclx/node_events.py.git
cd node_events.py
# hack on code
pip3 install . --user

许可证

Apache 2.0神奇的奥沃努比@miraclx)<;omiraculous@gmail.com>;

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
junit有没有办法在Java中重新初始化静态类?   在浏览器中点击应用程序时java Play框架挂起   文件Java错误中的NullPointerException   使用Java中的SNMP查找网络中计算机的登录名   java包装服务器引导程序已弃用,有什么替代方案?   当客户在等待理发时,java信号量值是否存在问题?   java如何使用JavaMail仅下载特定类型的附件   如何在java中将十进制转换为十六进制   java Slick2D粒子系统不会生成粒子   java检测更改事件来自何处   将Java集合类型参数类设置为数组   java如何从eclipse导出为可运行JAR文件?   java EntityManager对象未注入Glassfish和Spring   swing从actionPerformed和actionListener Java返回字符串   java在给定另一个等价键对象的情况下获取映射项的当前键   无论输入如何,java网络都会产生相同的输出