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

Function createStore

src/effector/createUnit.ts:252–454  ·  view source on GitHub ↗
(
  defaultState: State,
  props?: Config,
)

Source from the content-addressed store, hash-verified

250 'undefined is used to skip updates. To allow undefined as a value provide explicit { skipVoid: false } option'
251
252export function createStore<State>(
253 defaultState: State,
254 props?: Config,
255): Store<State> {
256 const config = flattenConfig(props)
257 const plainState = createStateRef(defaultState)
258 const errorTitle = generateErrorTitle('store', config)
259 const updates = createEvent({named: 'updates', derived: true})
260 applyTemplate('storeBase', plainState)
261 const plainStateId = plainState.id
262
263 // skipVoid deprecation rules
264 const explicitSkipVoid = 'skipVoid' in config
265 const voidValueAllowed = explicitSkipVoid && !config.skipVoid
266 const skipVoidTrueSet = explicitSkipVoid && config.skipVoid
267
268 deprecate(!skipVoidTrueSet, '{skipVoid: true}', 'updateFilter', errorTitle)
269
270 const store = {
271 updates,
272 defaultState,
273 stateRef: plainState,
274 getState() {
275 let targetRef = plainState
276 let reachedPage
277 if (currentPage) {
278 let page = currentPage
279 while (page && !page.reg[plainStateId]) {
280 page = getParent(page)
281 }
282 if (page) reachedPage = page
283 }
284 if (!reachedPage && forkPage) {
285 initRefInScope(forkPage, plainState, true)
286 reachedPage = forkPage
287 }
288 if (reachedPage) targetRef = reachedPage.reg[plainStateId]
289 return readRef(targetRef)
290 },
291 setState: (state: State) =>
292 launch({
293 target: store,
294 params: state,
295 defer: true,
296 scope: forkPage!,
297 }),
298 reset(...units: CommonUnit[]) {
299 assert(
300 // @ts-expect-error
301 store.targetable,
302 '.reset of derived store is not supported',
303 errorTitle,
304 )
305 forEach(units, unit =>
306 on(store, '.reset', unit, () => store.defaultState, errorTitle),
307 )
308 return store
309 },

Callers 15

array.live.jsFile · 0.90
object.live.jsFile · 0.90
object-fn.live.jsFile · 0.90
stores-fn.live.jsFile · 0.90
array-fn.live.jsFile · 0.90
mediaMatcherFunction · 0.90
createGateImplementationFunction · 0.90
rfc1.test.tsxFile · 0.90

Calls 15

flattenConfigFunction · 0.90
createStateRefFunction · 0.90
generateErrorTitleFunction · 0.90
applyTemplateFunction · 0.90
deprecateFunction · 0.90
launchFunction · 0.90
createNodeFunction · 0.90
calcFunction · 0.90
readFunction · 0.90
isVoidFunction · 0.90
userFnCallFunction · 0.90

Tested by 15

createCustomEntityFunction · 0.72
CompFunction · 0.72
createModelFunction · 0.72
createModelFunction · 0.72
createCustomEntityFunction · 0.72
fnFunction · 0.72
createQueryFunction · 0.72
factoryAFunction · 0.72
storeListFunction · 0.72
libFactoryFunction · 0.72
fabFunction · 0.72
createFieldFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…