@salla.sa/event

1.0.19 • Public • Published

Logo

Salla JS Events

Salla JS Events is based on the Event-Driven Architecture, which is a modern design approach centered on data that represents "events" (i.e., a product has been added to the cart).
Explore our blogs »

Report Bug · Request Feature . </Salla Developers> . Official Documentation

Table of Contents
  1. Overview
  2. Getting Started
  3. Usage
  • Support
  • Contributing
  • Credits
  • License
  • Overview

    In event-driven programming, an event is the result of a single or multiple actions. Subscribers can listen to that event and take action after it is released by the emitter. In other words, emitters can send events containing data that subscribers can use, and subscribers can use the data to do actions.

    Getting Started

    Salla JS Events uses EventEmitter2, which is an implementation of the EventEmitter module found in Node.js. It not only outperforms EventEmitter in benchmarks and is browser-compatible, but it also adds a slew of new non-breaking functionality to the EventEmitter interface.

    Installation

    Salla JS Events can be installed from the npm using the following commands:

    npm install @salla.sa/event --save

    Besides, this library is also available via the following public Content Delivery Network (CDN):

    <script src="https://cdn.jsdelivr.net/npm/@salla.sa/event@latest/dist/@salla.sa/event.min.js"></script>

    Usage

    Initially, the developer must import the Salla JS Events library as follows:

    import '@salla.sa/event'

    Salla JS Events can be triggered by the emitter's 'emit()' method. This method causes the event to be pushed using the data that the developer has provided.

    For example, the developer may create an event based on verified login by the user. Simply, the emit() method can be called with a list of parameters. These parameters state the event's action and the passed data along with it as below:

    // via event name
    Salla.event.emit("auth::verified",  {success:  true},  'email')

    Listening to the event

    After creating the event along with its list of data, the next step is to implement an appropriate listener for that event. In Salla JS Events, this can be achieved using two methods:

    • Using the event name and result directly along with an anonymized function to perform the needed action based on the event result.
    // via event name
    Salla.event.on('auth::verified',(response, authType)  =>  {
    // lets do anything when the event emit
    console.log('The customer has been verifed');
    console.log(response, authType)
    });
    • Adding a one time listener for the event along with an anonymized function to perform the needed action based on the event result.
    // Adds a one time listener for the event.
    Salla.event.once('auth::verified',(response, authType)  =>  {
    // The listener is invoked only the first time
    // the event is fired, after which it is removed.
    console.log('The customer has been verifed');
    console.log(response, authType)
    })

    (back to top)

    Support

    The team is always here to help you. Happen to face an issue? Want to report a bug? You can submit one here on Github using the Issue Tracker. If you still have any questions, please contact us via the Telegram Bot or join in the Global Developer Community on Telegram.

    (back to top)

    Contributing

    Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

    If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

    1. Fork the Project
    2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
    3. Commit your Changes (git commit -m 'Add some AmazingFeature')
    4. Push to the Branch (git push origin feature/AmazingFeature)
    5. Open a Pull Request

    (back to top)

    Credits

    (back to top)

    License

    The MIT License (MIT). Please see License File for more information.

    (back to top)

    Readme

    Keywords

    none

    Package Sidebar

    Install

    npm i @salla.sa/event

    Weekly Downloads

    75

    Version

    1.0.19

    License

    ISC

    Unpacked Size

    323 kB

    Total Files

    8

    Last publish

    Collaborators

    • a.djedaini
    • m.aljefri
    • malshoubaki
    • ahmed-alkatheri
    • ahmed-amlas
    • muhammed-sh
    • nullish-one
    • mostafaezzeldin
    • ahmed3mmar
    • mostafanabawy
    • hossamelsawy
    • egkrinkel
    • zafari8
    • mohanad7afiz
    • thaifani
    • ilyasabdul94
    • thegeeky
    • asm_sh_ali
    • kulth00m
    • salla.dev
    • naderm91
    • zymawy
    • omersamli
    • mohammad-altamimi
    • a-athamneh-salla
    • osama-k-salla-sa
    • khaled.almqayyad
    • abdulrahman_salla
    • maher-salla
    • dev_fouda
    • 4bdullatif
    • dhassanali
    • taghreedaaa
    • dhafer
    • elzakzouk
    • ashraf.reda
    • ahsanzaman2489
    • awaiskazmisalla
    • ali.arsalan177
    • jojomak13
    • devlomingo
    • hamzasalla
    • ghofranesalla
    • shimaa_hussein
    • ios96salla
    • ossycodes
    • owieselshaikh
    • abady009
    • osameyy
    • halsairi
    • alialjishi
    • abbasshdev
    • alquhaitsalla
    • waleed.salla
    • abubakermoharram
    • anhaar-ali-salla
    • mohammed_ashraaf
    • ali-mhd
    • hassankotti
    • iabdallah
    • canarydev41
    • ibra-hassan
    • dev-tarek
    • adelgs
    • anasred
    • salahmyn
    • anass_at
    • jalmatari
    • s.alkhwlani