Skip to content
This repository was archived by the owner on Jul 31, 2020. It is now read-only.

Commit 073c8b4

Browse files
committed
feat: use next-tick instead of asap
1 parent 6aecef3 commit 073c8b4

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"@semantic-release/git": "^7.0.7",
3636
"@semantic-release/npm": "^5.1.3",
3737
"@semantic-release/release-notes-generator": "^7.1.4",
38-
"@types/asap": "^2.0.0",
3938
"@types/jest": "^23.3.12",
39+
"@types/next-tick": "^1.0.0",
4040
"@types/webpack-env": "^1.13.6",
4141
"codecov": "^3.1.0",
4242
"commitlint": "^7.2.1",
@@ -58,6 +58,6 @@
5858
"mobx-state-tree": "^3.10.0"
5959
},
6060
"dependencies": {
61-
"asap": "^2.0.6"
61+
"next-tick": "^1.0.0"
6262
}
6363
}

src/createAsyncContainer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
hasParent,
88
} from 'mobx-state-tree';
99
import { now } from 'mobx-utils';
10-
import asap from 'asap';
10+
import nextTick from 'next-tick';
1111

1212
export interface VolatileAsyncContainerState {
1313
isReady: boolean;
@@ -113,7 +113,7 @@ export function createAsyncContainer<T extends IAnyModelType>(
113113
get value() {
114114
if (self.shouldFetch) {
115115
// Hack to allow side-effects in a view
116-
asap(() => {
116+
nextTick(() => {
117117
// Need to check shouldFetch again to avoid race-conditions
118118
// This is cheap since it's memoized
119119
if (self.shouldFetch) {

src/createAsyncStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ModelInstanceType,
1010
types,
1111
} from 'mobx-state-tree';
12-
import asap from 'asap';
12+
import nextTick from 'next-tick';
1313
import { createAsyncContainer } from './createAsyncContainer';
1414

1515
export type AsyncFetchActions<T> = (
@@ -205,7 +205,7 @@ export function createAsyncStore<T extends IAnyModelType>(
205205
self.containers.get(id) || AsyncContainer.create({ id } as any);
206206
if (ct.shouldFetch && !self.containers.has(id)) {
207207
// Hack to fool mobx into allowing side-effects in a view
208-
asap(() => {
208+
nextTick(() => {
209209
self.fetchOne(id, ct);
210210
});
211211
}
@@ -219,7 +219,7 @@ export function createAsyncStore<T extends IAnyModelType>(
219219
const ctsToFetch = cts.filter((ct) => ct && ct.shouldFetch);
220220
if (ctsToFetch.length > 0) {
221221
// Hack to fool mobx into allowing side-effects in a view
222-
asap(() => {
222+
nextTick(() => {
223223
self.fetchMany(ids, ctsToFetch);
224224
});
225225
}
@@ -228,7 +228,7 @@ export function createAsyncStore<T extends IAnyModelType>(
228228
getAll() {
229229
if (!self.isReady) {
230230
// Hack to fool mobx into allowing side-effects in a view
231-
asap(() => {
231+
nextTick(() => {
232232
self.fetchAll();
233233
});
234234
}

yarn.lock

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,16 @@
329329
into-stream "^4.0.0"
330330
lodash "^4.17.4"
331331

332-
"@types/asap@^2.0.0":
333-
version "2.0.0"
334-
resolved "https://registry.yarnpkg.com/@types/asap/-/asap-2.0.0.tgz#d529e9608c83499a62ae08c871c5e62271aa2963"
335-
integrity sha512-upIS0Gt9Mc8eEpCbYMZ1K8rhNosfKUtimNcINce+zLwJF5UpM3Vv7yz3S5l/1IX+DxTa8lTkUjqynvjRXyJzsg==
336-
337332
"@types/jest@^23.3.12":
338333
version "23.3.12"
339334
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.12.tgz#7e0ced251fa94c3bc2d1023d4b84b2992fa06376"
340335
integrity sha512-/kQvbVzdEpOq4tEWT79yAHSM4nH4xMlhJv2GrLVQt4Qmo8yYsPdioBM1QpN/2GX1wkfMnyXvdoftvLUr0LBj7Q==
341336

337+
"@types/next-tick@^1.0.0":
338+
version "1.0.0"
339+
resolved "https://registry.yarnpkg.com/@types/next-tick/-/next-tick-1.0.0.tgz#ab0e4680d31bacc5a60c962a19fe28c1cde73e83"
340+
integrity sha512-J9zljHWKO5EpdiJG9WHLE8Op6Zr34bTfeVw1hhRIRc9GHUVNKT0HdRUFAXOntT/ttl4BP9BJU2keR0C3pZXFdQ==
341+
342342
"@types/webpack-env@^1.13.6":
343343
version "1.13.6"
344344
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.6.tgz#128d1685a7c34d31ed17010fc87d6a12c1de6976"
@@ -590,7 +590,7 @@ arrify@^1.0.1:
590590
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
591591
integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=
592592

593-
asap@^2.0.0, asap@^2.0.6:
593+
asap@^2.0.0:
594594
version "2.0.6"
595595
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
596596
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
@@ -4645,6 +4645,11 @@ nerf-dart@^1.0.0:
46454645
resolved "https://registry.yarnpkg.com/nerf-dart/-/nerf-dart-1.0.0.tgz#e6dab7febf5ad816ea81cf5c629c5a0ebde72c1a"
46464646
integrity sha1-5tq3/r9a2Bbqgc9cYpxaDr3nLBo=
46474647

4648+
next-tick@^1.0.0:
4649+
version "1.0.0"
4650+
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
4651+
integrity sha1-yobR/ogoFpsBICCOPchCS524NCw=
4652+
46484653
nice-try@^1.0.4:
46494654
version "1.0.5"
46504655
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"

0 commit comments

Comments
 (0)