# Konfigurowanie komponentu i późniejsza rekonfiguracja

> Daj komponentowi opcje domyślne, nadpisz je w atrybucie config, reaguj w configure() i zmieniaj je w czasie działania przez reconfigure().

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

Drugi argument `COMPONENT()` zawiera opcje domyślne. Atrybut `config` elementu je nadpisuje, a deklaracja czyta scalone wartości z `config`. Zaimplementuj `self.configure(key, value)`, aby reagować, gdy opcja jest ustawiana lub zmieniana. W czasie działania `self.reconfigure('key:value;key2:value2')` (lub `CONFIG(selector, config)` dla wielu komponentów) zmienia opcje i wywołuje `configure` dla każdego zmienionego klucza.

```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>
```
