July 2018
Beginner
236 pages
5h 34m
English
The simplest way to create an observable is to use the observable() function. Take a look at the following:
const item = observable({ name: 'Party Balloons', itemId: '1234', quantity: 2, price: 10, coupon: { code: 'BIGPARTY', discountPercent: 50 }});
item is now an observable object and will start tracking changes to its properties. You can use this object as a regular JavaScript object without any special API to get or set its values. In the preceding snippet, you can also create an observable item using observable.object().
In the following snippet, we can see simple mutations made to the observables, like any regular JavaScript code:
// Set valuesitem.quantity += 3;item.name = 'Small Balloons';// Get valuesconsole ...
Read now
Unlock full access