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

Function useStoreMapBase

src/solid/lib/base.ts:111–174  ·  view source on GitHub ↗
(
  [configOrStore, separateFn]: [
    configOrStore:
      | {
          store: Store<State>
          keys: Keys
          fn(state: State, keys: Keys): Result
          updateFilter?: (update: Result, current: Result) => boolean
        }
      | Store<State>,
    separateFn?: (state: State, keys: Keys) => Result,
  ],
  scope?: Scope,
)

Source from the content-addressed store, hash-verified

109}
110
111export function useStoreMapBase<State, Result, Keys extends ReadonlyArray<any>>(
112 [configOrStore, separateFn]: [
113 configOrStore:
114 | {
115 store: Store<State>
116 keys: Keys
117 fn(state: State, keys: Keys): Result
118 updateFilter?: (update: Result, current: Result) => boolean
119 }
120 | Store<State>,
121 separateFn?: (state: State, keys: Keys) => Result,
122 ],
123 scope?: Scope,
124): Accessor<Result> {
125 let fn: (state: State, keys: Keys) => Result
126 let updateFilter: (update: Result, current: Result) => boolean =
127 basicUpdateFilter
128 let store: Store<State>
129 let keys: Keys
130 if (separateFn) {
131 fn = separateFn
132 store = configOrStore as Store<State>
133 keys = [] as unknown as Keys
134 } else {
135 fn = (configOrStore as any).fn
136 store = (configOrStore as any).store
137 keys = (configOrStore as any).keys
138 updateFilter = (configOrStore as any).updateFilter || basicUpdateFilter
139 }
140 if (!is.store(store)) throwError('useStoreMap expects a store')
141 if (!Array.isArray(keys)) throwError('useStoreMap expects an array as keys')
142 if (typeof fn !== 'function') throwError('useStoreMap expects a function')
143 const [result, setResult] = createSignal<{
144 fn: (state: State, keys: Keys) => Result
145 upd: (update: Result, current: Result) => boolean
146 val: Result
147 init: boolean
148 store: Store<State>
149 active: boolean
150 }>({} as any, {equals: false})
151 const refState = result()
152 refState.fn = fn
153 refState.upd = updateFilter
154 refState.init = refState.store === store
155 refState.store = store
156 refState.active = true
157 onCleanup(() => {
158 if (refState) {
159 refState.active = false
160 }
161 })
162 const inc = () => setResult(refState)
163
164 updateRef(stateReader(store, scope), keys, refState)
165 const stop = createWatch({
166 unit: store,
167 fn: val => updateRef(val, keys, refState, inc),
168 scope: scope,

Callers 2

useStoreMapFunction · 0.90
useStoreMapFunction · 0.90

Calls 6

throwErrorFunction · 0.90
createWatchFunction · 0.90
resultFunction · 0.85
updateRefFunction · 0.85
storeMethod · 0.80
stateReaderFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…