Skip to content
On this page

attachOperation since v0.6

DANGER

This operator is deprecated since v0.12 and will be removed in v0.14. Please read this ADR for more information and migration guide.

Creates new Query or Mutation on top of the existing one.

TIP

It is analog of attach from Effector for Queries or Mutations.

Formulae

attachOperation(query)

Creates new Query on top of the existing one.

ts
import { attachOperation, createQuery } from '@farfetched/core';

const originalQuery = createQuery({ handler: async () => 'some data' });
const attachedQuery = attachOperation(originalQuery);

attachOperation(query, { mapParams })

Creates new Query on top of the existing one, transforming its parameters through mapParams function.

ts
import { attachOperation, createQuery } from '@farfetched/core';

const originalQuery = createQuery({
  handler: async (params: string) => 'some data',
});

const attachedQuery = attachOperation(originalQuery, {
  mapParams: (params: number) => params.toString(),
});

attachOperation(query, { source, mapParams })

Creates new Query on top of the existing one, transforming its parameters through mapParams function with accept a value from source Store as a second argument.

ts
import { createStore } from 'effector';
import { attachOperation, createQuery } from '@farfetched/core';

const $externalStore = createStore(12);

const originalQuery = createQuery({
  handler: async (params: string) => 'some data',
});

const attachedQuery = attachOperation(originalQuery, {
  source: $externalStore,
  mapParams: (params: number, externalSource) => (params + externalSource).toString(),
});

attachOperation(mutation)

Creates new Mutation on top of the existing one.

ts
import { attachOperation, createMutation } from '@farfetched/core';

const originalMutation = createMutation({ handler: async () => 'some data' });
const attachedMutation = attachOperation(originalMutation);

attachOperation(mutation, { mapParams })

Creates new Mutation on top of the existing one, transforming its parameters through mapParams function.

ts
import { attachOperation, createMutation } from '@farfetched/core';

const originaMutation = createMutation({
  handler: async (params: string) => 'some data',
});

const attachedMutation = attachOperation(originaMutation, {
  mapParams: (params: number) => params.toString(),
});

attachOperation(mutation, { source, mapParams })

Creates new Mutation on top of the existing one, transforming its parameters through mapParams function with accept a value from source Store as a second argument.

ts
import { createStore } from 'effector';
import { attachOperation, createMutation } from '@farfetched/core';

const $externalStore = createStore(12);

const originalMutation = createMutation({
  handler: async (params: string) => 'some data',
});

const attachedMutation = attachOperation(originalMutation, {
  source: $externalStore,
  mapParams: (params: number, externalSource) => (params + externalSource).toString(),
});

Showcases

Released under the MIT License.