Skip to content

NZME/event-abstract-class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis Build

Event abstract class

ES6 abstract class to extend and allow classes to support native object event binding/triggering.

Example

import EventAbstractClass from 'event-abstract-class'

class Example extends EventAbstractClass {
    constructor () {
        super()
        
        this.value = null
    }
    
    setValue (value) {
        let oldValue = this.value
    
        this.trigger('setValue:pre', {
            newValue: value
        })
        
        this.value = value
        
        this.trigger('setValue:post', {
            newValue: value,
            oldValue: oldValue
        })
    }
}

let example = new Example()

example.on('setValue:post', (args) => {
    console.log('oldValue', args.oldValue)
    console.log('newValue', args.newValue)
})

example.setValue('New value 1!')
example.setValue('New value 2!')

About

event-abstract-class

Resources

Stars

Watchers

Forks

Packages

No packages published