Action

Action is to reduce the number of dependency tracking triggers, it can collect all changes, and then merge trigger.

1
import { Action } from "dob"

Features

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { observe, observable, Action } from 'dob'

const obj = observable({
a: 1
})

observe(() => {
console.log('dynamicObj.a change to', obj.a)
})

Action(()=> {
obj.a = 2
obj.a = 3
obj.a = 4
obj.a = 5
})

There are three changes can be seen merged.

ESNext usage

1
2
3
4
@Action someAction() {
obj.a = 2
obj.a = 3
}

In StrictMode

Changes only allowed run in Action in the strictMode.

note: async await seems like synchronization, in fact, is asynchronous, so it’s necessary to pay attention to the following wording:

1
2
3
4
5
6
7
8
@Action async someAction() {
this.store.isLoading = true
const result = await fetch("..")
Action(()=>{
this.store.isLoading = false
this.store.result = result
})
}

the code after await row, will be in a separate stack to run, that is, not in the current Action.