@xassist/xassist-eventdispatcher

    1.0.2 • Public • Published

    @xassist/xassist-eventdispatcher

    This module creates a general EventDispatcher class The class can beused to add listneres, and fire events.

    Installation

    If you use NPM, you can install the module via npm install xassist-eventdispatcher. Otherwise, you can download the latest minified file. Be aware any dependencies are not installed by default; you should consider downloading them yourself. If you want, you can install the complete library from github xassist, this includes all dependencies you may need.

    The module uses UMD and supports AMD, CommonJS and vanilla environments. Using vanilla: the xaglobal is exported:

    <script>
    xa.EventDispatcher()
    </script> 

    API

    EventDispatcher()

    The base function is the constructor-function for the class EventDispatcher.

    EventDispatcher()
    new EventDispatcher()

    new is not needed since the constructor checks for the use of the keyword. EventDispatcher() requires no parameters.

    Result for EventDispatcher()

    EventDispatcher() returns a new class instance of the Class EventDispatcher

    EventDispatcher(a).constructor.name===EventDispatcher

    EventDispatcher returns 6 method:

    • registerEvent(): the method to register the events, so listeners can get attached
    • hasEvent(): a method to check if an event is registered
    • on(): add a listener to an event
    • once(): add a listener to an event, which will be removed when the event is fired the first time
    • fire(): fires an event
    • off(): removes a specific listener from an event

    EventDispatcher has 1 own attributes:

    • _event[Object]:here all registered events and listeners are stored

    EventDispatcher().registerEvent()

    EventDispatcher().registerEvent() registers events so it can be triggered in the future

    EventDispatcher().registerEvent(eventName [,defaultThis])

    Parameters for EventDispatcher().registerEvent()

    EventDispatcher().registerEvent() takes 2 parameters:

    • eventName [String]:a string with the name for the event itself
    • defaultThis [any datatype,defaults to: this]:the default execution-context for the listeners

    Result for EventDispatcher().registerEvent()

    registerEvent returns an error if the event was registered before.

    EventDispatcher().hasEvent()

    The method EventDispatcher().hasEvent() checks if an event was registered before.

    EventDispatcher().hasEvent(eventName)

    Parameters for EventDispatcher().hasEvent()

    EventDispatcher().hasEvent() takes 1 parameters:

    • eventName [String]:a string with the name for the event itself

    Result for EventDispatcher().hasEvent()

    It returns a boolean indicating if the event was registered.

    EventDispatcher().on()

    The method EventDispatcher().on() adds a listener for a certain event.

    EventDispatcher().on(eventName,callBack [, thisArg])

    EventDispatcher().on() returns nothing.

    Parameters for EventDispatcher().on()

    EventDispatcher().on() takes 3 parameters:

    • eventName [String]:a string with the name for the event itself.
    • callBack [Function]:the function which needs to be executed when the event is trigered
    • thisArg [any datatype,defaults to: defaultThis]:an optional reference for thisArg, the callBack will be binded on trigger of the event (not before, so you could change the callBack if needed)

    EventDispatcher().once()

    The method EventDispatcher().once() adds a listener for a certain event.

    EventDispatcher().once(eventName,callBack [, thisArg])

    once() is exactly the same the same as on(), but the listener will only gets executed once, even when the event is trigerred multiple times. EventDispatcher().once() returns nothing.

    Parameters for EventDispatcher().once()

    EventDispatcher().once() takes 3 parameters:

    • eventName [String]:a string with the name for the event itself.
    • callBack [Function]:the function which needs to be executed when the event is trigered
    • thisArg [any datatype,defaults to: defaultThis]:an optional reference for thisArg, the callBack will be binded on trigger of the event (not before, so you could change the callBack if needed)

    EventDispatcher().off()

    The method EventDispatcher().off() removes a listener for a certain event.

    EventDispatcher().off(eventName,callBack )

    EventDispatcher().off() returns nothing.

    Parameters for EventDispatcher().off()

    EventDispatcher().off() takes 2 parameters:

    • eventName [String]:a string with the name for the event itself.
    • callBack [Function]:the listener which needs to be removed

    EventDispatcher().fire()

    The method EventDispatcher().fire() fires an event.

    EventDispatcher().fire(eventName /*list of other arguments*/ )

    EventDispatcher().fire() returns nothing.

    Parameters for EventDispatcher().fire()

    EventDispatcher().fire() takes 2 parameters:

    • eventName [String]:a string with the name for the event itself.
    • /list or arguments/ [any datatype]:all other arguments that will be passed to the listeners as arguments

    DevDependencies

    • csv2readme: read csv file with fixed format and parse a readme markdown file
    • rimraf: A deep deletion module for node (like rm -rf)
    • rollup: Next-generation ES6 module bundler
    • tape: tap-producing test harness for node and browsers

    License

    This module is licensed under the terms of GPL-3.0.

    Install

    npm i @xassist/xassist-eventdispatcher

    DownloadsWeekly Downloads

    15

    Version

    1.0.2

    License

    GPL-3.0

    Unpacked Size

    106 kB

    Total Files

    20

    Last publish

    Collaborators

    • beirens