BasicEventHandler

BasicEventHandler

The basic event handler for classes
This class will generates JQuery on, off, one, trigger events
And will add onReady hook

Constructor

new BasicEventHandler()

Source:

Methods

off(evt, fn)

Description:
  • Removes an event
    Equal to $(document).off()

Source:
Since:
  • 4.3.20
Example
trans.off('transLoaded', (e, opt)=> {
	// do something
})
Parameters:
Name Type Description
evt String

Event name

fn function

Function to trigger

on(evt, fn)

Description:
  • Create a new event with JQuery eventing convenience
    Equal to $(document).on()

Source:
Since:
  • 4.3.20 trans.on('transLoaded', (e, opt)=> { // do something })
Parameters:
Name Type Description
evt String

Event name

fn function

Function to trigger

one(evt, fn)

Description:
  • Run the event once
    Trigger an event and immediately removes it
    Equal to $(document).one()

Source:
Since:
  • 4.3.20
Parameters:
Name Type Description
evt String

Event name

fn function

Function to trigger

processWith(processName, value) → {*}

Description:
  • Add a custom process to a value.

Source:
Parameters:
Name Type Description
processName String

Name of the process

value *

Value to be processed

Returns:
  • By default will return value as is
Type
*

rejectState(state, erroropt)

Description:
  • Reject a state

Source:
Parameters:
Name Type Attributes Description
state String

State name

error String <optional>

Error message

resolveState(state, argopt)

Description:
  • Resolve a state

Source:
Parameters:
Name Type Attributes Description
state String

State name

arg * <optional>

Arguments to be passed to until

trigger(evt, fn)

Description:
  • Trigger an event
    Equal to $(document).trigger()

Source:
Since:
  • 4.3.20
Parameters:
Name Type Description
evt String

Event name

fn function

Function to trigger

(async) until(state) → {Promise.<*>}

Description:
  • State monitor. Wait until a state is resolved.
    Will wait until resolveState is called.
    Will immidiately executed if resolveState is already called

Source:
Since:
  • 4.12.4
Examples

Basic usage

await basicEventHandler.until("ready");

Asynchronous chaining

basicEventHandler.until("ready")
.then((result) = >{
	console.log(result);
})

basicEventHandler.resolveState("ready", "Hello world");
// prints: Hello world

Immidiately executed if `resolveState` with the same state has already been called

basicEventHandler.resolveState("ready", "App is ready");

var msg = await basicEventHandler.until("ready");
console.log(msg);
//immidately prints "App is ready"
Parameters:
Name Type Description
state String

State name

Returns:
  • Returns any variables passed on resolveState
Type
Promise.<*>

Type Definitions

Event

Description:
  • BasicEventHandler's event. This itself extends the standard Event API for html element. So, you can use the default element's event such as click, focus, blur, etc.
    Methods that uses Event are: on(), off(), one(), trigger()

Source:
See:

BasicEventHandler's event. This itself extends the standard Event API for html element. So, you can use the default element's event such as click, focus, blur, etc.
Methods that uses Event are: on(), off(), one(), trigger()

Type:
  • Event

State

Description:
  • Javascript's Promise type event handler.
    The state will switch from off to on once. And after that, it will stay in that state forever, so any further until() call will be resolved immidiately.
    Methods that uses Event are: until(), resolveState(), rejectState()

Source:
Since:
  • 4.12.1

Javascript's Promise type event handler.
The state will switch from off to on once. And after that, it will stay in that state forever, so any further until() call will be resolved immidiately.
Methods that uses Event are: until(), resolveState(), rejectState()

Type:
  • Promise