1.3.0 • Published 5 years ago

eventsystemx v1.3.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

this package holds two classes EventSystem, meant to provide the same functionality as C#'s event keyword does, and Box to synergize with it. js already has an Event class built in but that class is aimed to be used with html elements where this is meant to be more generic.

example

class Player{
    constructor(){
        this.deathEvent = new EventSystem()
        this.health = new Box(100)
        
        this.health.onchange.listen((value) => {
            if(value < 0){
                this.deathEvent.trigger()
            }
        })
    }
}

EventSystem

constructor()
simply initializes an eventsystem ('change' or 'death' for example)

listen(callback(value))
adds a callback that will be called when the event is triggered

deafen(callback)
removes a callback from the eventsystem. make sure the function is you pass to this function is the exact same one you added with listen else it doesn't work.

trigger(value)
causes all functions that are listening to be called with the supplied value.

Box

constructor(value)
creates a Box with a value

Box.value
internal value

Box.onchange
an eventsystem that will be triggered when the internal value changes

Box.batHearing
same as Box.onchange but is also triggered when Box.set is called with silent set to true

get()
gets the internal value (not strictly nescessary but for completeness sake)

set(value,silent:bool)
sets the internal and triggers the onchange event

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago