MCPcopy Create free account
hub / github.com/effector/effector / scopeBind

Function scopeBind

src/effector/fork/scopeBind.ts:6–39  ·  view source on GitHub ↗
(
  unit: (...args: any[]) => any,
  {scope, safe}: {scope?: Scope; safe?: true} = {},
)

Source from the content-addressed store, hash-verified

4
5/** bind event to scope */
6export function scopeBind(
7 unit: (...args: any[]) => any,
8 {scope, safe}: {scope?: Scope; safe?: true} = {},
9) {
10 assert(scope || forkPage || safe, 'scopeBind: scope not found')
11 const targetForkPage = scope || forkPage!
12
13 return (...args: any[]) => {
14 let final: any
15 let failed = false
16
17 const lastForkPage = forkPage
18 function restoreLastForkPage() {
19 setForkPage(lastForkPage)
20 }
21
22 setForkPage(targetForkPage)
23 try {
24 final = unit(...args)
25 } catch (err) {
26 final = err
27 failed = true
28 }
29 restoreLastForkPage()
30
31 if (failed) throw final
32
33 if (final instanceof Promise) {
34 final.then(restoreLastForkPage, restoreLastForkPage)
35 }
36
37 return final
38 }
39}

Callers 12

useUnitBaseFunction · 0.90
useEventBaseFunction · 0.90
dumbFunction · 0.90
useUnitBaseFunction · 0.90
scopeBind.test.tsFile · 0.90
useUnitFunction · 0.90
useEventFunction · 0.90
nameClashCheckFunction · 0.90
app.tsxFile · 0.90
app.tsxFile · 0.90
nameClashCheckFunction · 0.85
imports-globals.jsFile · 0.85

Calls 4

assertFunction · 0.90
setForkPageFunction · 0.90
unitFunction · 0.85
restoreLastForkPageFunction · 0.85

Tested by 3

dumbFunction · 0.72
nameClashCheckFunction · 0.72
nameClashCheckFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…