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

Function createSampling

src/effector/sample.ts:89–243  ·  view source on GitHub ↗
(
  method: string,
  clock: DataCarrier | DataCarrier[] | void,
  source: DataCarrier | Array<Store<any>> | Record<string, Store<any>> | void,
  filter: any,
  target: DataCarrier | DataCarrier[] | void,
  fn: any,
  name: string | undefined,
  metadata: object | void,
  batch: boolean,
  targetMayBeStore: boolean,
  filterRequired: boolean,
  sid?: string | undefined,
)

Source from the content-addressed store, hash-verified

87}
88
89export const createSampling = (
90 method: string,
91 clock: DataCarrier | DataCarrier[] | void,
92 source: DataCarrier | Array<Store<any>> | Record<string, Store<any>> | void,
93 filter: any,
94 target: DataCarrier | DataCarrier[] | void,
95 fn: any,
96 name: string | undefined,
97 metadata: object | void,
98 batch: boolean,
99 targetMayBeStore: boolean,
100 filterRequired: boolean,
101 sid?: string | undefined,
102) => {
103 const errorTitle = generateErrorTitle(method, metadata)
104 const isUpward = !!target
105 assert(
106 !isVoid(source) || !isVoid(clock),
107 fieldErrorMessage(errorTitle, 'either source or clock'),
108 )
109 let sourceIsClock = false
110 if (isVoid(source)) {
111 sourceIsClock = true
112 } else if (!is.unit(source)) {
113 source = combine(source)
114 }
115 if (isVoid(clock)) {
116 /** still undefined! */
117 clock = source
118 } else {
119 assertNodeSet(clock, errorTitle, 'clock')
120 if (Array.isArray(clock)) {
121 clock = createLinkNode(clock as CommonUnit[], [], [], method)
122 }
123 }
124 if (sourceIsClock) {
125 source = clock
126 }
127 if (!metadata && !name) {
128 /**
129 * When there is no metadata and name, assign source name as a fallback.
130 * This is very misleading behavior (sample unit is not a source unit)
131 * introduced a long time ago, so we keep it only for backward compatibility
132 * for cases which were covered at the time.
133 *
134 * Therefore, this name will not be used as a fallback for newer (23.4.0) cases
135 * (a.k.a. sample support for patronum debug traces)
136 * and metadata will not be created
137 */
138 name = (source as any).shortName
139 } else if (metadata && name) {
140 /** name field from sample config (from user) has highest priority */
141 ;(metadata as any).name = name
142 } else if (!metadata && name) {
143 /**
144 * metadata comes from plugin, so when name is present and metadata is missing,
145 * we need to create fresh metadata with name
146 */

Callers 3

splitFunction · 0.90
guardFunction · 0.90
sampleFunction · 0.85

Calls 15

generateErrorTitleFunction · 0.90
assertFunction · 0.90
isVoidFunction · 0.90
combineFunction · 0.90
assertNodeSetFunction · 0.90
createLinkNodeFunction · 0.90
isFunctionFunction · 0.90
assertTargetFunction · 0.90
readRefFunction · 0.90
getStoreStateFunction · 0.90
createStoreFunction · 0.90
createEventFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…