Working with actions and observables

In this section, we are going to learn to use observables and actions. The following code snippet declares a Store named ActorStore:

import { ActorInterface } from "../../universal/entities/actor"; 
import * as mobx from "mobx"; 
import { provide } from "../config/ioc"; 
import { TYPE } from "../contants/types"; 
import * as interfaces from "../interfaces"; 
 
const { observable, action, runInAction, configure } = mobx; 
configure({ enforceActions: true }); 
 
@provide(TYPE.ActorStore) 
export class ActorStore implements interfaces.ActorStore { 

The ActorStore is a class that is decorated with the @provide decorators. This decorator is used to allow us to inject the Store into other elements in the application.

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.