# Read, change and watch the state

> Use SET, GET, UPD, PUSH and WATCH to work with the global state and react when a path changes.

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

The state is one global object addressed by **paths** such as `cart.items`. The functions to work with it:

- `SET(path, value)` writes a value and notifies everything bound to the path
- `GET(path)` reads a value
- `UPD(path)` notifies the path after you changed the object in place (`GET('cart').discount = 5; UPD('cart')`)
- `PUSH(path, value)` appends to an array and notifies; with a `^` before the path it adds the value to the beginning
- `WATCH(path, callback)` runs the callback with the new value every time the path changes; join several paths with `+`

```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>
	<p><ui-bind path="cart.items" config="text:value ? value.length + ' items' : 'empty'"></ui-bind></p>

	<script>

		var log = [];

		WATCH('cart.items', function(value) {
			log.push(value.length);
		});

		SET('cart.items', []);
		PUSH('cart.items', 'book');
		PUSH('^cart.items', 'pen');

		GET('cart.items').push('lamp');
		UPD('cart.items');

	</script>

</body>
</html>
```
