# Configura un componente y reconfigúralo después

> Dale a un componente opciones por defecto, sobrescríbelas en el atributo config, reacciona en configure() y cámbialas en ejecución con reconfigure().

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: es
Content-SHA256: 93b1453d28131dffed51798b3a8d45375f034647831dd559609ce81f1b456224
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

El segundo argumento de `COMPONENT()` contiene las opciones por defecto. El atributo `config` del elemento las sobrescribe, y la declaración lee los valores combinados desde `config`. Implementa `self.configure(key, value)` para reaccionar cuando se define o cambia una opción. En ejecución, `self.reconfigure('key:value;key2:value2')` (o `CONFIG(selector, config)` para muchos componentes) cambia opciones y llama a `configure` por cada clave cambiada.

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-component name="badge" config="label:Sale"></ui-component>
	<ui-component name="badge" id="second"></ui-component>

	<script>

		COMPONENT('badge', 'color:blue;label:New', function(self, config) {

			self.make = function() {
				self.html('<b class="label"></b>');
				self.draw();
			};

			self.draw = function() {
				self.find('.label').text(config.label).css('color', config.color);
			};

			self.configure = function(key, value) {
				self.find('.label').length && self.draw();
			};

		});

	</script>

</body>
</html>
```
