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

Function attach

src/effector/attach.ts:22–134  ·  view source on GitHub ↗
(config: any)

Source from the content-addressed store, hash-verified

20import {Cmd, Node, Stack} from './index.h'
21
22export function attach(config: any) {
23 let injected
24 ;[config, injected] = processArgsToConfig(config, true)
25 const errorTitle = generateErrorTitle('attach', injected)
26 let {source, effect, mapParams, domain} = config
27 if (is.effect(effect)) {
28 assert(
29 isVoid(domain),
30 '`domain` can only be used with a plain function',
31 errorTitle,
32 )
33 }
34 const attached = createEffect(config, injected)
35 setMeta(attached, 'attached', true)
36 setUnitTrace(attached, getUnitTrace(attach))
37 const {runner} = getGraph(attached).scope as {runner: Node}
38 let runnerSteps: Array<Cmd>
39 const runnerFnStep = (upd: any, _: any, stack: Stack) => {
40 const {params, req, handler} = upd
41 const anyway = attached.finally
42 const rj = onSettled(params, req, false, anyway, stack)
43 const sourceData = stack.a
44 const isEffectHandler = is.effect(handler)
45 let ok = true
46 let computedParams
47 if (mapParams) {
48 ;[ok, computedParams] = runFn(mapParams, rj, [params, sourceData])
49 } else {
50 computedParams = source && isEffectHandler ? sourceData : params
51 }
52 if (ok) {
53 if (isEffectHandler) {
54 launch({
55 target: handler as any,
56 params: {
57 params: computedParams,
58 req: {
59 rs: onSettled(params, req, true, anyway, stack),
60 rj,
61 },
62 },
63 page: stack.page,
64 defer: true,
65 meta: stack.meta,
66 })
67 } else {
68 upd.args = [sourceData, computedParams]
69 return true
70 }
71 }
72 }
73 if (source) {
74 runner.scope.runnerFn = runnerFnStep
75 let state
76 if (is.store(source)) {
77 state = source
78 own(state, [attached])
79 } else {

Callers 15

useUnit.test.tsxFile · 0.90
scopes.test.tsxFile · 0.90
split.test.tsFile · 0.90
attach.test.tsFile · 0.90
createModelFunction · 0.90
is.test.tsFile · 0.90
domain.test.tsFile · 0.90
inspect.test.tsFile · 0.90
attach.test.tsFile · 0.90
factoryAFunction · 0.90
multiPass.test.tsFile · 0.90
index.test.tsFile · 0.90

Calls 15

processArgsToConfigFunction · 0.90
generateErrorTitleFunction · 0.90
assertFunction · 0.90
isVoidFunction · 0.90
createEffectFunction · 0.90
setMetaFunction · 0.90
setUnitTraceFunction · 0.90
getUnitTraceFunction · 0.90
getGraphFunction · 0.90
ownFunction · 0.90
combineFunction · 0.90
calcFunction · 0.90

Tested by 4

createModelFunction · 0.72
factoryAFunction · 0.72
nameClashCheckFunction · 0.72
fFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…