Skip to content
On this page

createBarrier since v0.11

Creates a Barrier object.

Formulae

createBarrier({ active, perform? })

ts
import { createBarrier } from '@farfetched/core';
import { combine } from 'effector';

const authBarrier = createBarrier({
  active: combine({ token: $token, now: $now }, ({ token, now }) => parseToken(token.exp) > now),
  perform: [renewTokenMutationFx],
});

Configuration fields:

  • active: Store with boolean that indicates whether Barrier is active or not.
  • perform?: optional array of Performers, that will be started in case some operation that uses this Barrier is started and Barrier is $active.

createBarrier({ activateOn, perform })

ts
import { createBarrier, isHttpError } from '@farfetched/core';
import { combine } from 'effector';

const authBarrier = createBarrier({
  activateOn: {
    failure: isHttpError(401),
  },
  perform: [renewTokenMutationFx],
});

Configuration fields:

  • activateOn.failure: callback that will be called in case of failure of some operation that uses this Barrier. If it returns true, Barrier will be activated.
  • perform: array of Performers, that will be started in case some operation that uses this Barrier is started and Barrier is $active.

createBarrier({ activateOn, deactivateOn })

ts
import { createBarrier } from '@farfetched/core';

const authBarrier = createBarrier({
  activateOn: userOpenedModal,
  deactivateOn: userClosedModal,
});

Configuration fields:

Performer

Any of the following form can be used in perform field:

  1. Query that does not accept any parameters
  2. Mutation that does not accept any parameters
  3. Effect that does not accept any parameters
  4. Object { start, end } where start and end are Events that do not accept any parameters. start Event will be called when the Barrier is activated, end Event is expected to be called when the performer is finished.

Released under the MIT License.