Snapshot Manager

There are times when saving the local state in the server becomes useful. For example, you may want to give the user a PDF representing their local state.

For such cases, Akita provides the snapshotManager API.

To get a snapshot of the whole application state, you can call the getStoresSnapshot() method:

import { snapshotManager } from '@datorama/akita';
export class SomeService {
saveState() {
this.http.post('/url', snapshotManager.getStoresSnapshot());
}
}

The getStoresSnapshot() returns an object containing the whole application state. For example:

{
"todos": {
"entities": { ... }
},
"cart": {
"entities": { ... }
},
"session": {
"firstName": "",
...
}
}

The whole state is defined by the state of every Akita store in your application

If you don't need the whole application state, you can pass the specific stores that you need:

import { snapshotManager } from '@datorama/akita';
export class SomeService {
saveState() {
this.http.post('/url', snapshotManager.getStoresSnapshot(['todos', 'posts']));
}
}

It also works the other way around, when you get the snapshot from the server you can save it by calling the setStoresSnapshot() method and passing the snapshot:

import { snapshotManager } from '@datorama/akita';
export class SomeService {
setSnapshotFromServer(snapshotFromServer) {
snapshotManager.setStoresSnapshot(snapshotFromServer);
}
}