Skip to content
generated from supranim/starter

Supranim's Event Emitter, allowing you to subscribe & listen for various events within your application

License

Notifications You must be signed in to change notification settings

supranim/emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supranim Events Emitter
Supranim's Event Emitter - Subscribe & listen for various events within your application

✨ Key features

  • Framework Agnostic
  • Available in ⚡️ Supranim Framework
  • Persistent Memory w/ Supranim Storage driver
  • Dependency-free
  • Open Source | MIT License

Install

nimble install emitter

Examples

Listeners can receive data as varargs[Arg] objects, containing a public value field of Any object. Check std/typeinfo

Framework agnostic usage

# somewhere in your main application
Event.listen("account.email.changed") do(args: varargs[Arg]):
    echo "Email address has been changed."
    # do the do, send confirmation mails, etc...

# somewhere in your proc-based ``POST`` or ``UPDATE`` controller
let newEmailAddress = "new.address@example.com"
Event.emit("account.email.changed", newArg(newEmailAddress))

Emitter from Supranim

For apps based on Supranim Application Template. Note that all listeners should be stored inside events/listeners directory.

In Supranim is highly recommended to create a .nim file for each branch of your application logic. For example, account.nim should hold all listeners related to accounts (email updates, password reset requests and so on).

For loading listeners into your application is recommended to use include, instead of import. Listener files can be included in the main state of your application (this is usually the main .nim file of your project.)

TODO. Create new listeners using Sup, the Command Line Interface of your Supranim application

# src/events/listeners/account.nim

Event.listen("account.email.update") do(args: varargs[Arg]):
    echo "The email address has been changed."

Event.listen("account.password.reset.request") do(args: varargs[Arg]):
    echo "Request for password reset."

Event.listen("account.password.update") do(args: varargs[Arg]):
    echo "Password has been changed."

❤ Contributions

If you like this project you can contribute to this project by opening new issues, fixing bugs, contribute with code, ideas and you can even donate via PayPal address 🥰

👑 Discover Nim language

What's Nim? Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Find out more about Nim language

Why Nim? Performance, fast compilation and C-like freedom. We want to keep code clean, readable, concise, and close to our intention. Also a very good language to learn in 2022.

🎩 License

Events is an Open Source Software released under MIT license. Made by Humans from OpenPeep.
Copyright © 2022 Supranim & OpenPeep — All rights reserved.

About

Supranim's Event Emitter, allowing you to subscribe & listen for various events within your application

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages