MCPcopy Create free account
hub / github.com/effect-app/libs / makeStreamMutation2

Function makeStreamMutation2

packages/vue/src/mutate.ts:441–483  ·  view source on GitHub ↗
(queryInvalidator: QueryInvalidator<RInvalidator>)

Source from the content-addressed store, hash-verified

439 return useMutation
440}
441
442export const useMakeMutation = <RInvalidator>(queryInvalidator: QueryInvalidator<RInvalidator>) => {
443 /**
444 * Pass a function that returns an Effect, e.g from a client action.
445 * Executes query cache invalidation based on default rules or provided option.
446 * When `I = void` the input argument may be omitted.
447 */
448 const useMutation = <I, E, A, R, Request extends Req, Id extends string>(
449 self: RequestHandlerWithInput<I, A, E, R, Request, Id>
450 ): MutationFn<I, A, E, R, Id> => {
451 const r = (i: I, options?: MutationOptionsBase) =>
452 invalidateQueries(self, options, queryInvalidator)(self.handler(i), i)
453 return Object.assign(r, { id: self.id }) as any
454 }
455 return useMutation
456}
457
458/**
459 * Returns a stream-based mutation factory for use with `streamFn`.
460 * The outer Effect sets up per-invocation invalidation scaffolding
461 * and returns a stream that triggers query invalidation via `Stream.ensuring` when it completes.
462 *
463 * Use with `streamFn` / `Command.streamFn(id)(mutateHandler, ...combinators)` so that
464 * the command manages its own reactive state internally.
465 */
466export const makeStreamMutation2 = <RInvalidator>(queryInvalidator: QueryInvalidator<RInvalidator>) => {
467 return (
468 self: {
469 id: string
470 options?: ClientForOptions
471 disableQueryInvalidation?: boolean
472 handler: (i: any) => Stream.Stream<any, any, any>
473 },
474 mergedInvalidation?: MutationOptionsBase["queryInvalidation"]
475 ) => {
476 const invCache = buildInvalidateCache(self, mergedInvalidation, queryInvalidator)
477
478 const makeInvocationEffect = (input: unknown, source: Stream.Stream<any, any, any>) =>
479 Effect.gen(function*() {
480 const keysRef = yield* Ref.make<ReadonlyArray<InvalidationKey>>([])
481 // Server invalidation keys stay settlement-only: flushing them from `add` refetched
482 // live queries once per chunk (One-Pick List storms). Write-deps flush once when the
483 // first write arrives (job create → GetActiveJob) and again from `ensuring`.
484 const invKeys = makeInvalidationKeysService(keysRef)
485 const readsRef = yield* Ref.make(DataDependencies.empty())
486 const writesRef = yield* Ref.make(DataDependencies.empty())

Callers 1

useStreamMutation2Function · 0.90

Calls 3

buildInvalidateCacheFunction · 0.85
makeInvocationEffectFunction · 0.85
handlerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…