@effect-app/vue 4.0.0-beta.75 → 4.0.0-beta.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/withToast.ts CHANGED
@@ -36,7 +36,7 @@ export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>, WaiR, S
36
36
  export class WithToast extends Context.Service<WithToast>()("WithToast", {
37
37
  make: Effect.gen(function*() {
38
38
  const toast = yield* Toast
39
- return <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
39
+ return <A, E, Args extends readonly unknown[], R, WaiR = never, SucR = never, ErrR = never>(
40
40
  options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
41
41
  ) =>
42
42
  Effect.fnUntraced(function*(self: Effect.Effect<A, E, R>, ...args: Args) {
@@ -71,7 +71,10 @@ describe("alt2", () => {
71
71
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
72
72
  })),
73
73
  Effect.tap(() =>
74
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
74
+ Effect.currentSpan.pipe(
75
+ Effect.map((_) => _.name),
76
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
77
+ )
75
78
  ),
76
79
  Effect.tap(() => Effect.sync(() => executed = true))
77
80
  )
@@ -125,7 +128,10 @@ it.live("works", () =>
125
128
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
126
129
  })),
127
130
  Effect.tap(() =>
128
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
131
+ Effect.currentSpan.pipe(
132
+ Effect.map((_) => _.name),
133
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
134
+ )
129
135
  ),
130
136
  Effect.tap(() => Effect.sync(() => executed = true))
131
137
  )
@@ -175,7 +181,10 @@ it.live("works non-gen", () =>
175
181
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
176
182
  })),
177
183
  Effect.tap(() =>
178
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
184
+ Effect.currentSpan.pipe(
185
+ Effect.map((_) => _.name),
186
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
187
+ )
179
188
  ),
180
189
  Effect.tap(() => Effect.sync(() => executed = true))
181
190
  )
@@ -317,7 +326,10 @@ it.live("with toasts", () =>
317
326
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
318
327
  })),
319
328
  Effect.tap(() =>
320
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
329
+ Effect.currentSpan.pipe(
330
+ Effect.map((_) => _.name),
331
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
332
+ )
321
333
  ),
322
334
  // WithToast.handle({
323
335
  // onFailure: "failed",
@@ -471,7 +483,10 @@ it.live("works with alt", () =>
471
483
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
472
484
  })),
473
485
  Effect.tap(() =>
474
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
486
+ Effect.currentSpan.pipe(
487
+ Effect.map((_) => _.name),
488
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
489
+ )
475
490
  ),
476
491
  Effect.tap(() => Effect.sync(() => executed = true))
477
492
  )
@@ -624,7 +639,10 @@ it.live("with toasts with alt", () =>
624
639
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
625
640
  })),
626
641
  Effect.tap(() =>
627
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
642
+ Effect.currentSpan.pipe(
643
+ Effect.map((_) => _.name),
644
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
645
+ )
628
646
  ),
629
647
  Command.withDefaultToast(),
630
648
  Effect.tap(() => Effect.sync(() => executed = true))
@@ -758,3 +776,55 @@ it.live("defect with alt", () =>
758
776
  expect(toasts.length).toBe(1) // toast should show error
759
777
  expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
760
778
  }))
779
+
780
+ describe("state-in-toast", () => {
781
+ it("works", () => {
782
+ const toasts: any[] = []
783
+ const removeMutation = Object.assign(
784
+ Effect.fn(function*(_item: string) {
785
+ yield* Effect.sleep(1000)
786
+ }),
787
+ { id: "remove_thing" }
788
+ )
789
+
790
+ const item = "x"
791
+
792
+ const Command = useExperimental({ toasts, messages: DefaultIntl.en })
793
+
794
+ Command.fn(removeMutation, {
795
+ state: () => ({ item }),
796
+ waitKey: (id) => `${id}.${item}`,
797
+ blockKey: () => `modify_thing.${item}`
798
+ // allowed: () => role.value === "admin"
799
+ })(
800
+ function*() {
801
+ // yield* Command.confirmOrInterrupt(yield* I18n.formatMessage({ id: "confirm.remove_item" }, { item }))
802
+ yield* removeMutation(item)
803
+ },
804
+ Command.withDefaultToast({
805
+ onSuccess: (a, b, c, d) => {
806
+ console.log("Success", { a, b, c, d })
807
+ expectTypeOf(d.state).toEqualTypeOf<{ readonly item: "x" }>()
808
+ }
809
+ })
810
+ )
811
+
812
+ Command.fn(removeMutation, {
813
+ state: () => ({ item }),
814
+ waitKey: (id) => `${id}.${item}`,
815
+ blockKey: () => `modify_thing.${item}`
816
+ // allowed: () => role.value === "admin"
817
+ })(
818
+ function*() {
819
+ // yield* Command.confirmOrInterrupt(yield* I18n.formatMessage({ id: "confirm.remove_item" }, { item }))
820
+ yield* removeMutation(item)
821
+ },
822
+ Command.withDefaultToast({
823
+ onSuccess: (a, b, c) => {
824
+ console.log("Success", { a, b, c })
825
+ expectTypeOf(c).toEqualTypeOf<undefined>()
826
+ }
827
+ })
828
+ )
829
+ })
830
+ })
@@ -1 +1 @@
1
- {"version":3,"file":"form.test.d.ts","sourceRoot":"","sources":["../form.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,CAAC,EAAE,MAAM,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,qBAAa,YAAa,SAAQ,iBAahC;CAAG;;;;AAEL,qBAAa,mBAAoB,SAAQ,wBAEvC;CAAG;;;;;;;;;;;AAEL,qBAAa,WAAY,SAAQ,gBAK/B;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;;;;AAEL,cAAM,QAAS,SAAQ,aAGrB;CAAG;;;;;;;;;;;;;;;;;;;;;;;AAqBL,qBAAa,cAAe,SAAQ,mBAGlC;CAAG"}
1
+ {"version":3,"file":"form.test.d.ts","sourceRoot":"","sources":["../form.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,CAAC,EAAE,MAAM,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,qBAAa,YAAa,SAAQ,iBAahC;CAAG;;;;AAEL,qBAAa,mBAAoB,SAAQ,wBAEvC;CAAG;;;;;;;;;;;;AAEL,qBAAa,WAAY,SAAQ,gBAK/B;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;;;;;AAEL,cAAM,QAAS,SAAQ,aAGrB;CAAG;;;;;;;;;;;;;;;;;;;;;;;;AAqBL,qBAAa,cAAe,SAAQ,mBAGlC;CAAG"}