Skip to content

crelte / plugins / Events

Class: Events

Constructors

Constructor

ts
new Events(): Events;

Returns

Events

Properties

inner

ts
inner: Map<string, Set<any>>;

Methods

getListeners()

ts
getListeners(ev): (cr) => 
  | Entry
  | Promise<Entry | null>
  | null[];

Get all listeners for an event

Parameters

ev

"loadEntry"

Returns

(cr) => | Entry | Promise<Entry | null> | null[]


has()

ts
has(ev): boolean;

Check if an event has listeners

Parameters

ev

string

Returns

boolean


on()

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"beforeRequest"

fn

(cr) => void | Promise<void>

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"loadGlobalData"

fn

(cr) => any

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"loadEntry"

fn

(cr) => | Entry | Promise<Entry | null> | null

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"beforeQueryEntry"

fn

(cr, vars) => void | Promise<void>

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"afterLoadEntry"

fn

(cr) => any

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"loadData"

fn

(cr, entry) => any

Returns

a function to remove the listener

ts
(): void;
Returns

void

Call Signature

ts
on(ev, fn): () => void;

Listens for an event.

beforeRequest

Please prefer to return not return a promise only if you need to wait for something. This allows a push request to be done without a microtask. Allowing for a better DX.

loadEntry

This will execute all listeners in sequence and stop on the first one which returns an entry. Will be executed in preload as well.

beforeQueryEntry

This allows to modify the entry query variables before the entry query is executed. Will be executed in preload as well.

afterLoadEntry

Will be executed in preload as well.

Parameters
ev

"beforeRender"

fn

(cr) => void

Returns

a function to remove the listener

ts
(): void;
Returns

void


remove()

ts
remove(ev, fn): void;

Remove a listener

Parameters

ev

string

fn

any

Returns

void


trigger()

Call Signature

ts
trigger(ev, cr): (void | Promise<void>)[];

Trigger an event

Parameters
ev

"beforeRequest"

cr

CrelteRequest

Returns

(void | Promise<void>)[]

Call Signature

ts
trigger(ev, cr): any[];

Trigger an event

Parameters
ev

"loadGlobalData"

cr

CrelteRequest

Returns

any[]

Call Signature

ts
trigger(
   ev, 
   cr, 
   vars): (void | Promise<void>)[];

Trigger an event

Parameters
ev

"beforeQueryEntry"

cr

CrelteRequest

vars

EntryQueryVars

Returns

(void | Promise<void>)[]

Call Signature

ts
trigger(ev, cr): any[];

Trigger an event

Parameters
ev

"afterLoadEntry"

cr

CrelteRequest

Returns

any[]

Call Signature

ts
trigger(
   ev, 
   cr, 
   entry): any[];

Trigger an event

Parameters
ev

"loadData"

cr

CrelteRequest

entry

Entry

Returns

any[]

Call Signature

ts
trigger(
   ev, 
   cr, 
   route): void[];

Trigger an event

Parameters
ev

"beforeRender"

cr

CrelteRequest

route

Route

Returns

void[]