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

Function createEvent

src/effector/createUnit.ts:152–226  ·  view source on GitHub ↗
(
  nameOrConfig?: any,
  maybeConfig?: any,
)

Source from the content-addressed store, hash-verified

150}
151
152export function createEvent<Payload = any>(
153 nameOrConfig?: any,
154 maybeConfig?: any,
155): Event<Payload> {
156 const config = flattenConfig({
157 or: maybeConfig,
158 and: typeof nameOrConfig === 'string' ? {name: nameOrConfig} : nameOrConfig,
159 }) as any
160 const errorTitle = generateErrorTitle('event', config)
161 const event = ((payload: Payload, ...args: unknown[]) => {
162 assert(
163 !getMeta(event, 'derived'),
164 'call of derived event is not supported, use createEvent instead',
165 errorTitle,
166 )
167 assert(
168 !isPure,
169 'unit call from pure function is not supported, use operators like sample instead',
170 errorTitle,
171 )
172 if (currentPage) {
173 return callCreate(event, template, payload, args)
174 }
175 return event.create(payload, args)
176 }) as Event<Payload>
177 const template = readTemplate()
178 const finalEvent = Object.assign(event, {
179 graphite: createNode({
180 meta: initUnit(
181 config.actualOp || EVENT,
182 event,
183 config,
184 getUnitTrace(createEvent),
185 ),
186 regional: true,
187 }),
188 create(params: Payload, _: any[]) {
189 launch({target: event, params, scope: forkPage!})
190 return params
191 },
192 watch: (fn: (payload: Payload) => any) => watchUnit(event, fn),
193 map: (fn: Function) => deriveEvent(event, MAP, fn, [userFnCall()]),
194 filter: (fn: {fn: Function}) =>
195 //@ts-expect-error
196 deriveEvent(event, 'filter', fn.fn ? fn : fn.fn, [
197 userFnCall(callStack, true),
198 ]),
199 filterMap: (fn: Function) =>
200 deriveEvent(event, 'filterMap', fn, [
201 userFnCall(),
202 calc(value => !isVoid(value), true),
203 ]),
204 prepend(fn: Function) {
205 assert(
206 // @ts-expect-error
207 event.targetable,
208 '.prepend of derived event is not supported, call source event instead',
209 errorTitle,

Callers 15

mediaMatcherFunction · 0.90
createComponentFunction · 0.90
createGateImplementationFunction · 0.90
rfc1.test.tsxFile · 0.90
index.test.tsxFile · 0.90
useStore.test.tsxFile · 0.90
useUnit.test.tsxFile · 0.90
createCustomEntityFunction · 0.90
useList.test.tsxFile · 0.90

Calls 15

flattenConfigFunction · 0.90
generateErrorTitleFunction · 0.90
assertFunction · 0.90
getMetaFunction · 0.90
readTemplateFunction · 0.90
createNodeFunction · 0.90
watchUnitFunction · 0.90
userFnCallFunction · 0.90
calcFunction · 0.90
isVoidFunction · 0.90
setMetaFunction · 0.90
reportDeclarationFunction · 0.90

Tested by 15

createCustomEntityFunction · 0.72
runEventFunction · 0.72
handlersFunction · 0.72
CompFunction · 0.72
dumbFunction · 0.72
createCustomEntityFunction · 0.72
fnFunction · 0.72
factoryFunction · 0.72
customOperatorFunction · 0.72
createQueryFunction · 0.72
factoryAFunction · 0.72
createFieldFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…