MCPcopy Index your code
hub / github.com/effector/effector / createGateImplementation

Function createGateImplementation

src/react/createGate.ts:9–77  ·  view source on GitHub ↗
({
  domain,
  defaultState,
  hook: useGateHook,
  mainConfig,
  maybeConfig,
}: {
  domain?: Domain
  defaultState: State | {}
  hook: typeof useGateBase
  mainConfig?: Record<string, any>
  maybeConfig?: Record<string, any> & {sid?: string}
})

Source from the content-addressed store, hash-verified

7import {isObject} from '../effector/is'
8
9export function createGateImplementation<State>({
10 domain,
11 defaultState,
12 hook: useGateHook,
13 mainConfig,
14 maybeConfig,
15}: {
16 domain?: Domain
17 defaultState: State | {}
18 hook: typeof useGateBase
19 mainConfig?: Record<string, any>
20 maybeConfig?: Record<string, any> & {sid?: string}
21}): Gate<State> {
22 const config = flattenConfig({
23 or: maybeConfig,
24 and: mainConfig,
25 }) as {sid: string | undefined; name: string | undefined}
26 const name = config.name || 'gate'
27 const fullName = `${domain ? `${domain.compositeName.fullName}/` : ''}${name}`
28 const set = createEvent<State>({
29 name: `${fullName}.set`,
30 sid: config.sid ? `${config.sid}|set` : undefined,
31 })
32 const open = createEvent<State>({
33 name: `${fullName}.open`,
34 sid: config.sid ? `${config.sid}|open` : undefined,
35 })
36 const close = createEvent<State>({
37 name: `${fullName}.close`,
38 sid: config.sid ? `${config.sid}|close` : undefined,
39 })
40 const status = createStore(Boolean(false), {
41 name: `${fullName}.status`,
42 serialize: 'ignore',
43 // doesn't need to have sid, because it is internal store, should not be serialized
44 })
45 .on(open, () => Boolean(true))
46 .on(close, () => Boolean(false))
47 const state = createStore(defaultState as State, {
48 name: `${fullName}.state`,
49 sid: config.sid,
50 })
51 .on(set, (_, state) => state)
52 .on(open, (_, state) => state)
53 .reset(close)
54 if (domain) {
55 const {hooks} = domain as any
56 launch({
57 target: [
58 hooks.store,
59 hooks.store,
60 hooks.event,
61 hooks.event,
62 hooks.event,
63 ] as any,
64 params: [status, state, open, close, set],
65 })
66 }

Callers 2

createGateFunction · 0.90
createGateFunction · 0.70

Calls 7

flattenConfigFunction · 0.90
createEventFunction · 0.90
createStoreFunction · 0.90
launchFunction · 0.90
withDisplayNameFunction · 0.90
onMethod · 0.65
resetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…