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, isHttpErrorCode } from '@farfetched/core';
import { combine } from 'effector';
const authBarrier = createBarrier({
activateOn: {
failure: isHttpErrorCode(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 returnstrue, 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:
activateOn: Event that will activate Barrier when called.deactivateOn: Event that will deactivate Barrier when called.
Performer
Any of the following form can be used in perform field:
- Query that does not accept any parameters
- Mutation that does not accept any parameters
- Effect that does not accept any parameters
- Object
{ start, end }wherestartandendare Events that do not accept any parameters.startEvent will be called when the Barrier is activated,endEvent is expected to be called when the performer is finished.