---
title: Eventos
project: jComponent V19
version: 19.194
section: reference
language: es
license: MIT
url: https://totaljs.es/docs/es/jcomponent-v19/19-194/reference/events/
updated: 2026-11-18T13:58:24.464Z
---

# Eventos

> Los eventos que emite la biblioteca.

Gestiona estos eventos con [ON()](../globals/#on) y elimina los manejadores con [OFF()](../globals/#off). Tus propios eventos usan las mismas funciones con [EMIT()](../globals/#emit).

## API

### ON('init', function() {})

Type: `event`

Se ejecuta una vez cuando los primeros componentes están listos, justo antes de `ready`.

Una página sin componentes no emite este evento.

Example: Ejemplo
```js
ON('init', function() {
	console.log('init'); // init
});
```

### ON('ready', function() {})

Type: `event`

Se ejecuta una vez cuando los primeros componentes están listos.

Un manejador registrado más tarde se ejecuta de inmediato. Una página sin componentes no emite este evento.

Example: Ejemplo
```js
ON('ready', function() {
	console.log('ready'); // ready
});
```

### ON('component', function(component) {})

Type: `event`

Se ejecuta cuando un componente está listo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | El componente. |

Example: Ejemplo
```js
ON('component', function(com) {
	console.log(com.path); // data.box
});
```

### ON('@name', function(component) {})

Type: `event`

Se ejecuta cuando un componente con este nombre está listo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | El componente. |

Example: Ejemplo
```js
ON('@box', function(com) {
	console.log(com.name); // box
});
```

### ON('#id', function(component) {})

Type: `event`

Se ejecuta cuando un componente con este identificador está listo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | El componente. |

Example: Ejemplo
```js
ON('#mybox', function(com) {
	console.log(com.id); // mybox
});
```

### ON('component.compile', function(name, declaration) {})

Type: `event`

Se ejecuta cuando se declara un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El nombre. |
| `declaration` | `Object` | yes |  | La declaración. |

Example: Ejemplo
```js
ON('component.compile', function(name) {
	console.log(name); // hello
});
COMPONENT('hello', NOOP);
```

### ON('component.destroy', function(name, component) {})

Type: `event`

Se ejecuta cuando se elimina un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El nombre. |
| `component` | `Component` | yes |  | El componente. |

Example: Ejemplo
```js
ON('component.destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('destroy', function(name, component) {})

Type: `event`

Se ejecuta cuando se elimina un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El nombre. |
| `component` | `Component` | yes |  | El componente. |

Example: Ejemplo
```js
ON('destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('lazy', function(name, loading) {})

Type: `event`

Se ejecuta cuando un componente lazy empieza y termina de cargarse.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El nombre. |
| `loading` | `Boolean` | yes |  | `true` al principio, `false` al final. |

Example: Ejemplo
```js
ON('lazy', function(name, loading) {
	console.log(name, loading); // box true
});
setTimeout(() => SETTER('box', 'hello', 'Peter'), 500);
```

### ON('binder', function(binder) {})

Type: `event`

Se ejecuta cuando un enlace de datos está listo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `binder` | `Object` | yes |  | El enlace. |

Example: Ejemplo
```js
ON('binder', function(binder) {
	console.log(binder.path); // user.name
});
```

### ON('plugin', function(plugin) {})

Type: `event`

Se ejecuta cuando se crea un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | El plugin. |

Example: Ejemplo
```js
ON('plugin', function(plugin) {
	console.log(plugin.name); // users
});
PLUGIN('users', NOOP);
```

### ON('plugin.destroy', function(plugin) {})

Type: `event`

Se ejecuta cuando se elimina un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | El plugin. |

Example: Ejemplo
```js
ON('plugin.destroy', function(plugin) {
	console.log(plugin.name); // users
});
// Declaring a plugin again removes the previous one
setTimeout(() => PLUGIN('users', NOOP), 300);
setTimeout(() => PLUGIN('users', NOOP), 600);
```

### ON('cmd', function(name, a, b, c, d, e) {})

Type: `event`

Se ejecuta antes de enviar un comando a los componentes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El comando. |
| `a` | `Object` | yes |  | Hasta cinco argumentos. |

Example: Ejemplo
```js
ON('cmd', function(name, value) {
	console.log(name, value); // refresh 1
});
CMD('refresh', 1);
```

### ON('exec', function(path, a, b, c, d) {})

Type: `event`

Se ejecuta antes de que [EXEC()](../globals/#exec) llame a una función o a un método de un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | El destino. |
| `a` | `Object` | yes |  | Hasta cuatro argumentos. |

Example: Ejemplo
```js
ON('exec', function(path, value) {
	console.log(path, value); // app.run 1
});
window.app = { run: NOOP };
EXEC('app.run', 1);
```

### ON('setter', function(selector, method, a, b) {})

Type: `event`

Se ejecuta antes de que [SETTER()](../globals/#setter) llame a los componentes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | El selector. |
| `method` | `String` | yes |  | El método. |
| `a` | `Object` | yes |  | Los dos primeros argumentos, `a` y `b`. |

Example: Ejemplo
```js
ON('setter', function(selector, method, value) {
	console.log(selector, method, value); // box hello 1
});
SETTER('box', 'hello', 1);
```

### ON('env', function(name, value) {})

Type: `event`

Se ejecuta cuando se escribe una variable de entorno.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | El nombre. |
| `value` | `Object` | yes |  | El valor. |

Example: Ejemplo
```js
ON('env', function(name, value) {
	console.log(name, value); // api /v1/
});
ENV('api', '/v1/');
```

### ON('import', function(url, target) {})

Type: `event`

Se ejecuta después de importar contenido.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | La URL. En el contenido HTML, empieza por `$import`. |
| `target` | `jQuery` | yes |  | El elemento de destino, o el elemento `script` o `link` creado. |

Example: Ejemplo
```js
ON('import', function(url, target) {
	console.log(target.length); // 1
});
IMPORT('/part.html');
```

### ON('request', function(options) {})

Type: `event`

Se ejecuta antes de enviar una petición.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `options` | `Object` | yes |  | La petición: `url`, `method`, `headers`, `data`, `upload`, `scope` y más. |

Asigna `options.cancel = true` para detener la petición. `options.respond(response, [headers])` la responde sin servidor, y `options.throw(response, [headers], code)` la responde con un error.

Example: Ejemplo
```js
ON('request', function(options) {
	console.log(options.method, options.url); // GET /api/
	options.respond({ ok: true });
});
AJAX('GET /api/', NOOP);
```

### ON('response', function(output) {})

Type: `event`

Se ejecuta cuando llega una respuesta, antes del callback de la petición.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | El resultado: `url`, `method`, `status`, `response`, `raw`, `headers`, `error`, `duration` y más. |

Asigna `output.process = false` para omitir el callback de la petición.

Example: Ejemplo
```js
ON('response', function(output) {
	console.log(output.status, output.response.ok); // 200 true
});
AJAX('GET /api/', NOOP);
```

### ON('error', function(output) {})

Type: `event`

Se ejecuta cuando falla una petición.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | El resultado de la petición. |

El evento no se emite cuando `DEF.ajaxerrors` es `true`.

Example: Ejemplo
```js
ON('error', function(output) {
	console.log(output.status); // 500
});
AJAX('GET /api/', NOOP);
```

### ON('ERROR', function(response) {})

Type: `event`

Se ejecuta cuando [ERROR()](../globals/#error) encuentra un error.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `response` | `Object` | yes |  | El valor comprobado. |

Example: Ejemplo
```js
ON('ERROR', function(response) {
	console.log(response[0].error); // Invalid
});
ERROR([{ error: 'Invalid' }]);
```

### ON('knockknock', function(counter) {})

Type: `event`

Se ejecuta cada minuto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | El número de ejecuciones. |

Example: Ejemplo
```js
ON('knockknock', function(counter) {
	console.log(counter); // 1
});
```

### ON('service', function(counter) {})

Type: `event`

Se ejecuta cada minuto, justo antes de `knockknock`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | El número de ejecuciones. |

Example: Ejemplo
```js
ON('service', function(counter) {
	console.log(counter); // 1
});
```

### ON('resize2', function() {})

Type: `event`

Se ejecuta después de que cambie el tamaño de la ventana.

Se retrasa 300 milisegundos, y también se ejecuta una vez cuando se inicia la página.

Example: Ejemplo
```js
ON('resize2', function() {
	console.log(typeof(WW)); // number
});
```

### ON('scroll', function(area) {})

Type: `event`

Se ejecuta cuando empieza el desplazamiento en un [SCROLLBAR()](../globals/#scrollbar).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | El elemento desplazado. |

Example: Ejemplo
```js
ON('scroll', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('scrollidle', function(area) {})

Type: `event`

Se ejecuta cuando se detiene el desplazamiento en un [SCROLLBAR()](../globals/#scrollbar).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | El elemento desplazado. |

Example: Ejemplo
```js
ON('scrollidle', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('visible', function(visible) {})

Type: `event`

Se ejecuta cuando la página pasa a segundo plano o vuelve de él.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `visible` | `Boolean` | yes |  | `true` cuando la página está visible. |

Example: Ejemplo
```js
ON('visible', function(visible) {
	console.log(visible); // true
});
$(window).trigger('visibilitychange');
```

### ON('@flag name', function(path, value, type) {})

Type: `event`

Se ejecuta cuando se usa un path o un método con el flag personalizado `@name`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | El path. |
| `value` | `Object` | yes |  | El valor. |
| `type` | `Number` | yes |  | El tipo de cambio. |

Example: Ejemplo
```js
ON('@flag saved', function(path, value) {
	console.log(path, value); // user.age 30
});
SET('user.age @saved', 30);
```
