| 158 | } |
| 159 | |
| 160 | canRun(mutation: Mutation<any, any, any, any>): boolean { |
| 161 | const scope = scopeFor(mutation) |
| 162 | if (typeof scope === 'string') { |
| 163 | const mutationsWithSameScope = this.#scopes.get(scope) |
| 164 | const firstPendingMutation = mutationsWithSameScope?.find( |
| 165 | (m) => m.state.status === 'pending', |
| 166 | ) |
| 167 | // we can run if there is no current pending mutation (start use-case) |
| 168 | // or if WE are the first pending mutation (continue use-case) |
| 169 | return !firstPendingMutation || firstPendingMutation === mutation |
| 170 | } else { |
| 171 | // For unscoped mutations there are never any pending mutations in front of the |
| 172 | // current mutation |
| 173 | return true |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> { |
| 178 | const scope = scopeFor(mutation) |