From 30fa8e8d1f9a8b01e64373c2fa9f1c167a365520 Mon Sep 17 00:00:00 2001 From: Eric Bower Date: Mon, 16 Dec 2024 13:29:56 -0500 Subject: [PATCH] chore: upgrade effection to v4 --- action.ts | 12 ++++++------ compose.ts | 2 +- deno.lock | 36 ++++++++++++++++++++++++++++++++++++ deps.ts | 4 ++-- fx/request.ts | 4 ++-- mdw/fetch.ts | 2 +- npm.ts | 4 ++-- query/thunk.ts | 4 ++-- store/batch.ts | 2 +- store/fx.ts | 6 +++--- store/store.ts | 2 +- test/api.test.ts | 12 +++++++----- test/batch.test.ts | 12 ++++++------ test/fetch.test.ts | 26 ++++++++++++++------------ test/mdw.test.ts | 6 +++--- test/put.test.ts | 2 +- test/store.test.ts | 8 ++++---- test/thunk.test.ts | 6 +++--- test/timer.test.ts | 35 ++++++++++++++++++++--------------- 19 files changed, 115 insertions(+), 70 deletions(-) diff --git a/action.ts b/action.ts index 52f14503..88d3f0c2 100644 --- a/action.ts +++ b/action.ts @@ -22,11 +22,11 @@ export const ActionContext = createContext( export function useActions(pattern: ActionPattern): Stream { return { - *subscribe() { - const actions = yield* ActionContext; + [Symbol.iterator]: function* () { + const actions = yield* ActionContext.expect(); const match = matcher(pattern); yield* SignalQueueFactory.set(() => createFilterQueue(match) as any); - return yield* actions.subscribe(); + return yield* actions; }, }; } @@ -49,7 +49,7 @@ export function emit({ } export function* put(action: AnyAction | AnyAction[]) { - const signal = yield* ActionContext; + const signal = yield* ActionContext.expect(); return emit({ signal, action, @@ -106,7 +106,7 @@ export function* takeLeading( } export function* waitFor( - predicate: Callable, + predicate: Callable | Promise | boolean>, ) { const init = yield* call(predicate as any); if (init) { @@ -115,7 +115,7 @@ export function* waitFor( while (true) { yield* take("*"); - const result = yield* call(() => predicate as any); + const result = yield* call(predicate as any); if (result) { return; } diff --git a/compose.ts b/compose.ts index 990b8612..cd55406b 100644 --- a/compose.ts +++ b/compose.ts @@ -28,7 +28,7 @@ export function compose( // last called middleware # let index = -1; - function* dispatch(i: number): Generator { + function* dispatch(i: number): Generator { if (i <= index) { throw new Error("next() called multiple times"); } diff --git a/deno.lock b/deno.lock index 426ea446..6424955f 100644 --- a/deno.lock +++ b/deno.lock @@ -141,6 +141,42 @@ "https://deno.land/x/effection@3.0.0-beta.3/lib/sleep.ts": "44e3a80248dad7a47066a99a7daec9b318e87d5d211adf27776145544d455689", "https://deno.land/x/effection@3.0.0-beta.3/lib/types.ts": "9738143fe6bfd5709a6ff10b6dd065582cfaca1167bf57902cb7bcca89b53dc4", "https://deno.land/x/effection@3.0.0-beta.3/mod.ts": "ffae461c16d4a1bf24c2179582ab8d5c81ad0df61e4ae2fba51ef5e5bdf90345", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/abort-signal.ts": "01b4bf70a27c505a2ba176fea7bb7e4774b9519ad8c67b25cbf3864b1b1bc192", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/action.ts": "bbba264043816bc628e51ad8fea41d9fc7397e27ac9f8e3accbae94c74d49b1f", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/all.ts": "47d3ea2715a5d3f91a17fb3899ee2fa57c67109e171e86f7ebfb87c07fae46f4", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/async.ts": "ac4bed095e849584a6170ac9a47c9217c2e1e99543275cbc9407d92851120ada", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/call.ts": "f9165ac3737d5fa2f2e1ded989f17437a9926abea4128453996a94aba8a89b4f", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/callcc.ts": "e5afe880abea9a6bd20ef99658975e2fc704486707c4fc95018d4ef44e15f370", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/channel.ts": "445b29c5cfc0b6bc48b1a7ea81e09d14c452ee4646c49c7753c8e5b34962ad50", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/constant.ts": "cbf8724addd990ee4acad629c596a03b3aecc8557671a8a5911960eb984cc2a7", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/context.ts": "1b1e979beec34339a5d8b3d926deca71fe8d05517ef445b27a8a011c258f70b6", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/contexts.ts": "5a56c139d3db9198721bab26a72907ce772a4ab7e890f2691e650753159cccdb", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/coroutine.ts": "1a24ba17607353a1b99b2f553ac4c18bf48710d4941781cfcc4eef01bb402856", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/do.ts": "027d412d672ad67e32eb29fefd69be08655ef2dd0e032f52ddc019e9899153a6", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/drain.ts": "90966c1ee86b6d1215e8d478b097ebab158d6afc9bfd21c5a827e1126d1eee62", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/each.ts": "7e630e29ef4030fa742fa2ba18f5b3ba6761ef5eb2f8322311c5af18bcc6cad2", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/ensure.ts": "8e5b804ace7c90fc4c1349531e52edc3c31ee3c78c77667138888a84719b177e", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/events.ts": "32fa772fa2f18a61fa9b8daaa6d17093d5d5d77586c62f8e2e9c3a2329044375", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/lazy-promise.ts": "ac5b41cc4321df370fb9b375d2bc6681f9b381553ee60c9974299573417ce776", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/lift.ts": "a623de97bc2206d45669780274441c4123ec6664e8085984c7e073a4b30e34ed", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/main.ts": "ac958f15c4277a4b92f746da38e9adb6bc7f3d0778b49443c64da0c1993984ee", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/maybe.ts": "e64f5d5da4273c2e4785e3d1c55ba457d5314a8039d138747fe80cabbb4d6d94", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/mod.ts": "a7e3ca090c1b71b5a798b542be1e14707ad422713136aa3beb860b064151d47f", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/queue.ts": "0242c92921d82c671fe345d88ca31a7f66b6d49c20fb63a0079dc07c917a305f", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/race.ts": "88b7d0b7f5ef4e566a193e2e76eb574d95304f891c8ff12ca9a53c1a612375a7", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/reducer.ts": "e0e229143083dfa8ffd12663dcdd10ea5247ebda5fd837a91a0cc7a5a4117aa4", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/resource.ts": "af10f469ac2bb9b984a56840311f30c9d677f1ffe97b22541d99b6060150f649", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/result.ts": "9b413a0af84825a4935ee9ff78ebec1649acc1e3e74e19c0c391dbf025104245", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/run.ts": "1d461ad5318e52ec5226c35c36a9c70acdb8363526554d8f649f76650f61a770", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/scope.ts": "e121646a90c9938f167e814f24f4d51bf831ca5d6341ff0105df1d3da1b3a8f3", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/signal.ts": "9b0975f62e6fa010029fdabe9368fa873d1f94ed05964952b621856c090cbd27", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/sleep.ts": "51fdecc512321c23c75efec2d58b3e0d1846bc25c35b487fb5fc1c169a9ad858", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/spawn.ts": "b209abeaf572800b6bf8b7357f3a87bd7aeb573687cde23b5de352f8fbef8b3f", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/suspend.ts": "6c93e8ba438719df3acc4ce52362837b5dc6bdab68e90e4e4d0b7eda818585c1", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/task.ts": "d3b3bb22b7b184b7f0000cc84aa8730dfd9112c8dc97b5b01512c7b842e842c8", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/types.ts": "7f0a53612aeb8cfe5fe2bd26212241963216094eebbc1e81bc9a64531cffc8c5", + "https://deno.land/x/effection@4.0.0-alpha.3/lib/with-resolvers.ts": "d85013be2c996f3cd7a8c2b11948123647eb070d75d225636bb495d5b9edc71d", + "https://deno.land/x/effection@4.0.0-alpha.3/mod.ts": "ffae461c16d4a1bf24c2179582ab8d5c81ad0df61e4ae2fba51ef5e5bdf90345", "https://deno.land/x/expect@v0.3.0/expect.ts": "5e6717eddc9df376f7b2c9be6403e016130bb2edbb1acd261a2d6ea9608ee196", "https://deno.land/x/expect@v0.3.0/matchers.ts": "a37ef4577739247af77a852cdcd69484f999a41ad86ec16bb63a88a7a47a2372", "https://deno.land/x/expect@v0.3.0/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914", diff --git a/deps.ts b/deps.ts index 34169cd5..59016d90 100644 --- a/deps.ts +++ b/deps.ts @@ -13,7 +13,7 @@ export type { Stream, Subscription, Task, -} from "https://deno.land/x/effection@3.0.0-beta.3/mod.ts"; +} from "https://deno.land/x/effection@4.0.0-alpha.3/mod.ts"; export { action, call, @@ -35,7 +35,7 @@ export { suspend, useAbortSignal, useScope, -} from "https://deno.land/x/effection@3.0.0-beta.3/mod.ts"; +} from "https://deno.land/x/effection@4.0.0-alpha.3/mod.ts"; import React from "https://esm.sh/react@18.2.0?pin=v135"; export { React }; diff --git a/fx/request.ts b/fx/request.ts index 32218ff1..825ccb09 100644 --- a/fx/request.ts +++ b/fx/request.ts @@ -2,11 +2,11 @@ import { call, useAbortSignal } from "../deps.ts"; export function* request(url: string | URL | Request, opts?: RequestInit) { const signal = yield* useAbortSignal(); - const response = yield* call(fetch(url, { signal, ...opts })); + const response = yield* call(() => fetch(url, { signal, ...opts })); return response; } export function* json(response: Response) { - const result = yield* call(response.json()); + const result = yield* call(() => response.json()); return result; } diff --git a/mdw/fetch.ts b/mdw/fetch.ts index 466900f5..14554e6d 100644 --- a/mdw/fetch.ts +++ b/mdw/fetch.ts @@ -230,7 +230,7 @@ export function* request( const { url, ...req } = ctx.req(); const request = new Request(url, req); - const result = yield* safe(fetch(request)); + const result = yield* safe(() => fetch(request)); if (result.ok) { ctx.response = result.value; } else { diff --git a/npm.ts b/npm.ts index 0983e3f8..f0bdd6ff 100644 --- a/npm.ts +++ b/npm.ts @@ -23,9 +23,9 @@ async function init() { }, ], mappings: { - "https://deno.land/x/effection@3.0.0-beta.3/mod.ts": { + "https://deno.land/x/effection@4.0.0-alpha.3/mod.ts": { name: "effection", - version: "3.0.0-beta.3", + version: "4.0.0-alpha.3", }, "https://esm.sh/react@18.2.0?pin=v135": { name: "react", diff --git a/query/thunk.ts b/query/thunk.ts index 2f6ec6cf..b6e85ab9 100644 --- a/query/thunk.ts +++ b/query/thunk.ts @@ -255,13 +255,13 @@ export function createThunks>( } function* register() { - storeId = yield* IdContext; + storeId = yield* IdContext.expect(); if (storeId && storeMap.has(storeId)) { console.warn("This thunk instance is already registered."); return; } - signal = yield* ActionContext; + signal = yield* ActionContext.expect(); storeMap.set(storeId, signal); yield* ensure(function* () { diff --git a/store/batch.ts b/store/batch.ts index cd56b272..c5b4bf3c 100644 --- a/store/batch.ts +++ b/store/batch.ts @@ -9,7 +9,7 @@ export function createBatchMdw( return function* batchMdw(_: UpdaterCtx, next: Next) { if (!notifying) { notifying = true; - yield* action(function* (resolve) { + yield* action((resolve) => () => { queue(() => { notifying = false; resolve(); diff --git a/store/fx.ts b/store/fx.ts index 623a24a3..8264238e 100644 --- a/store/fx.ts +++ b/store/fx.ts @@ -10,7 +10,7 @@ import { getIdFromAction, take } from "../action.ts"; export function* updateStore( updater: StoreUpdater | StoreUpdater[], ): Operation> { - const store = yield* StoreContext; + const store = yield* StoreContext.expect(); // had to cast the store since StoreContext has a generic store type const st = store as FxStore; const ctx = yield* st.update(updater); @@ -26,7 +26,7 @@ export function* select( selectorFn: (s: S, p?: P) => R, p?: P, ): Operation { - const store = yield* StoreContext; + const store = yield* StoreContext.expect(); return selectorFn(store.getState() as S, p); } @@ -57,7 +57,7 @@ export function* waitForLoaders( actions: (ThunkAction | ActionFnWithPayload)[], ) { const group = yield* parallel( - actions.map((action) => waitForLoader(loaders, action)), + actions.map((action) => () => waitForLoader(loaders, action)), ); return yield* group; } diff --git a/store/store.ts b/store/store.ts index fcc8f8a1..51c740f2 100644 --- a/store/store.ts +++ b/store/store.ts @@ -103,7 +103,7 @@ export function createStore({ } function* notifyChannelMdw(_: UpdaterCtx, next: Next) { - const chan = yield* StoreUpdateContext; + const chan = yield* StoreUpdateContext.expect(); yield* chan.send(); yield* next(); } diff --git a/test/api.test.ts b/test/api.test.ts index cbf0eed0..0ccf297d 100644 --- a/test/api.test.ts +++ b/test/api.test.ts @@ -105,10 +105,12 @@ it(tests, "POST", async () => { store.dispatch(createUser({ email: mockUser.email })); - await store.run(waitFor(function* (): Operation { - const res = yield* select((state: AnyState) => state.users["1"].id); - return res !== ""; - })); + await store.run(() => + waitFor(function* (): Operation { + const res = yield* select((state: AnyState) => state.users["1"].id); + return res !== ""; + }) + ); expect(store.getState().users).toEqual({ "1": { id: "1", name: "test", email: "test@test.com" }, @@ -297,7 +299,7 @@ it(tests, "with hash key on a large post", async () => { const action = createUserDefaultKey({ email, largetext }); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const s = store.getState(); const expectedKey = createKey(action.payload.name, { diff --git a/test/batch.test.ts b/test/batch.test.ts index d7107fbb..59d14779 100644 --- a/test/batch.test.ts +++ b/test/batch.test.ts @@ -24,12 +24,12 @@ it(batch, "should batch notify subscribers based on mdw", async () => { }); await store.run(function* () { const group: any = yield* parallel([ - schema.update(schema.cache.add({ "1": "one" })), - schema.update(schema.cache.add({ "2": "two" })), - schema.update(schema.cache.add({ "3": "three" })), - schema.update(schema.cache.add({ "4": "four" })), - schema.update(schema.cache.add({ "5": "five" })), - schema.update(schema.cache.add({ "6": "six" })), + () => schema.update(schema.cache.add({ "1": "one" })), + () => schema.update(schema.cache.add({ "2": "two" })), + () => schema.update(schema.cache.add({ "3": "three" })), + () => schema.update(schema.cache.add({ "4": "four" })), + () => schema.update(schema.cache.add({ "5": "five" })), + () => schema.update(schema.cache.add({ "6": "six" })), ]); yield* group; // make sure it will still notify subscribers after batched round diff --git a/test/fetch.test.ts b/test/fetch.test.ts index 7fe2d3dd..b2c59cab 100644 --- a/test/fetch.test.ts +++ b/test/fetch.test.ts @@ -61,7 +61,7 @@ it( const action = fetchUsers(); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const state = store.getState(); expect(state.cache[action.payload.key]).toEqual(mockUser); @@ -106,7 +106,7 @@ it( const action = fetchUsers(); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const data = "this is some text"; expect(actual).toEqual({ ok: true, value: data }); @@ -142,7 +142,7 @@ it(tests, "error handling", async () => { const action = fetchUsers(); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const state = store.getState(); expect(state.cache[action.payload.key]).toEqual(errMsg); @@ -181,7 +181,7 @@ it(tests, "status 204", async () => { const action = fetchUsers(); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const state = store.getState(); expect(state.cache[action.payload.key]).toEqual({}); @@ -220,7 +220,7 @@ it(tests, "malformed json", async () => { const action = fetchUsers(); store.dispatch(action); - await store.run(waitForLoader(schema.loaders, action)); + await store.run(() => waitForLoader(schema.loaders, action)); const data = { message: "Unexpected token 'o', \"not json\" is not valid JSON", @@ -261,7 +261,7 @@ it(tests, "POST", async () => { const action = fetchUsers(); store.dispatch(action); - const loader = await store.run(waitForLoader(schema.loaders, action)); + const loader = await store.run(() => waitForLoader(schema.loaders, action)); if (!loader.ok) { throw loader.error; } @@ -324,7 +324,7 @@ it(tests, "POST multiple endpoints with same uri", async () => { store.dispatch(action2); const results = await store.run( - waitForLoaders(schema.loaders, [action1, action2]), + () => waitForLoaders(schema.loaders, [action1, action2]), ); if (!results.ok) { throw results.error; @@ -443,7 +443,7 @@ it( const action = fetchUsers(); store.dispatch(action); - const loader = await store.run(waitForLoader(schema.loaders, action)); + const loader = await store.run(() => waitForLoader(schema.loaders, action)); if (!loader.ok) { throw loader.error; } @@ -484,7 +484,7 @@ it( const action = fetchUsers(); store.dispatch(action); - const loader = await store.run(waitForLoader(schema.loaders, action)); + const loader = await store.run(() => waitForLoader(schema.loaders, action)); if (!loader.ok) { throw loader.error; } @@ -515,7 +515,9 @@ it( store.run(api.bootup); store.dispatch(fetchUsers()); - const loader = await store.run(waitForLoader(schema.loaders, fetchUsers)); + const loader = await store.run(() => + waitForLoader(schema.loaders, fetchUsers) + ); if (!loader.ok) { throw loader.error; } @@ -545,7 +547,7 @@ it(tests, "should use dynamic mdw to mock response", async () => { const dynamicUser = { id: "2", email: "dynamic@starfx.com" }; fetchUsers.use(mdw.response(new Response(JSON.stringify(dynamicUser)))); store.dispatch(fetchUsers()); - let loader = await store.run(waitForLoader(schema.loaders, fetchUsers)); + let loader = await store.run(() => waitForLoader(schema.loaders, fetchUsers)); if (!loader.ok) { throw loader.error; } @@ -554,7 +556,7 @@ it(tests, "should use dynamic mdw to mock response", async () => { // reset dynamic mdw and try again api.reset(); store.dispatch(fetchUsers()); - loader = await store.run(waitForLoader(schema.loaders, fetchUsers)); + loader = await store.run(() => waitForLoader(schema.loaders, fetchUsers)); if (!loader.ok) { throw loader.error; } diff --git a/test/mdw.test.ts b/test/mdw.test.ts index f4b3fe2f..79ab41a2 100644 --- a/test/mdw.test.ts +++ b/test/mdw.test.ts @@ -400,7 +400,7 @@ it(tests, "createApi with own key", async () => { store.dispatch(createUserCustomKey({ email: newUEmail })); - await store.run(waitForLoader(schema.loaders, createUserCustomKey)); + await store.run(() => waitForLoader(schema.loaders, createUserCustomKey)); const expectedKey = theTestKey ? `/users [POST]|${theTestKey}` @@ -469,7 +469,7 @@ it(tests, "createApi with custom key but no payload", async () => { store.run(query.bootup); store.dispatch(getUsers()); - await store.run(waitForLoader(schema.loaders, getUsers)); + await store.run(() => waitForLoader(schema.loaders, getUsers)); const expectedKey = theTestKey ? `/users [GET]|${theTestKey}` @@ -571,7 +571,7 @@ it(tests, "stub predicate", async () => { store.run(api.bootup); store.dispatch(fetchUsers()); - await store.run(waitFor(() => actual.ok)); + await store.run(() => waitFor(() => actual.ok)); expect(actual).toEqual({ ok: true, diff --git a/test/put.test.ts b/test/put.test.ts index 5b6f71fa..d899079d 100644 --- a/test/put.test.ts +++ b/test/put.test.ts @@ -8,7 +8,7 @@ it(putTests, "should send actions through channel", async () => { const actual: string[] = []; function* genFn(arg: string) { - const actions = yield* ActionContext; + const actions = yield* ActionContext.expect(); const task = yield* spawn(function* () { for (const action of yield* each(actions)) { actual.push(action.type); diff --git a/test/store.test.ts b/test/store.test.ts index 80b1395b..ccd88233 100644 --- a/test/store.test.ts +++ b/test/store.test.ts @@ -64,9 +64,9 @@ it( await scope.run(function* (): Operation[]> { const result = yield* parallel([ function* () { - const store = yield* StoreContext; - const chan = yield* StoreUpdateContext; - const msgList = yield* chan.subscribe(); + const store = yield* StoreContext.expect(); + const chan = yield* StoreUpdateContext.expect(); + const msgList = yield* chan; yield* msgList.next(); asserts.assertEquals(store.getState(), { users: { 1: { id: "1", name: "eric" }, 3: { id: "", name: "" } }, @@ -163,7 +163,7 @@ it(tests, "resets store", async () => { dev: true, }); - await store.run(store.reset(["users"])); + await store.run(() => store.reset(["users"])); asserts.assertEquals(store.getState(), { users: { 3: { id: "3", name: "hehe" } }, diff --git a/test/thunk.test.ts b/test/thunk.test.ts index f3790435..b99fcd73 100644 --- a/test/thunk.test.ts +++ b/test/thunk.test.ts @@ -413,7 +413,7 @@ it(tests, "middleware order of execution", async () => { store.run(api.bootup); store.dispatch(action()); - await store.run(waitFor(() => acc === "abcdefg")); + await store.run(() => waitFor(() => acc === "abcdefg")); asserts.assert(acc === "abcdefg"); }); @@ -445,7 +445,7 @@ it(tests, "retry with actionFn", async () => { store.run(api.bootup); store.dispatch(action()); - await store.run(waitFor(() => acc === "agag")); + await store.run(() => waitFor(() => acc === "agag")); asserts.assertEquals(acc, "agag"); }); @@ -475,7 +475,7 @@ it(tests, "retry with actionFn with payload", async () => { store.run(api.bootup); store.dispatch(action({ page: 1 })); - await store.run(waitFor(() => acc === "agag")); + await store.run(() => waitFor(() => acc === "agag")); asserts.assertEquals(acc, "agag"); }); diff --git a/test/timer.test.ts b/test/timer.test.ts index bd050496..184e40c7 100644 --- a/test/timer.test.ts +++ b/test/timer.test.ts @@ -7,9 +7,10 @@ it(tests, "should call thunk at most once every timer", async () => { let called = 0; await run(function* () { yield* spawn(function* () { - yield* timer(10)("ACTION", function* () { - called += 1; - }); + yield* timer(10)("ACTION", () => + function* () { + called += 1; + }); }); yield* put({ type: "ACTION", payload: { key: "my-key" } }); yield* sleep(1); @@ -25,9 +26,10 @@ it(tests, "should let user cancel timer", async () => { let called = 0; await run(function* () { yield* spawn(function* () { - yield* timer(10_000)("ACTION", function* () { - called += 1; - }); + yield* timer(10_000)("ACTION", () => + function* () { + called += 1; + }); }); yield* put({ type: "ACTION", payload: { key: "my-key" } }); yield* sleep(1); @@ -41,9 +43,10 @@ it(tests, "should let user cancel timer with action obj", async () => { let called = 0; await run(function* () { yield* spawn(function* () { - yield* timer(10_000)("ACTION", function* () { - called += 1; - }); + yield* timer(10_000)("ACTION", () => + function* () { + called += 1; + }); }); const action = { type: "ACTION", payload: { key: "my-key" } }; yield* put(action); @@ -58,14 +61,16 @@ it(tests, "should let user cancel timer with wildcard", async () => { let called = 0; await run(function* () { yield* spawn(function* () { - yield* timer(10_000)("ACTION", function* () { - called += 1; - }); + yield* timer(10_000)("ACTION", () => + function* () { + called += 1; + }); }); yield* spawn(function* () { - yield* timer(10_000)("WOW", function* () { - called += 1; - }); + yield* timer(10_000)("WOW", () => + function* () { + called += 1; + }); }); yield* put({ type: "ACTION", payload: { key: "my-key" } }); yield* put({ type: "WOW", payload: { key: "my-key" } });