(store_values, store_name, store)
| 241 | * @returns {V} |
| 242 | */ |
| 243 | export function store_get(store_values, store_name, store) { |
| 244 | if (DEV) { |
| 245 | validate_store(store, store_name.slice(1)); |
| 246 | } |
| 247 | |
| 248 | // it could be that someone eagerly updates the store in the instance script, so |
| 249 | // we should only reuse the store value in the template |
| 250 | if (store_name in store_values && store_values[store_name][0] === store) { |
| 251 | return store_values[store_name][2]; |
| 252 | } |
| 253 | |
| 254 | store_values[store_name]?.[1](); // if store was switched, unsubscribe from old store |
| 255 | store_values[store_name] = [store, null, undefined]; |
| 256 | const unsub = subscribe_to_store( |
| 257 | store, |
| 258 | /** @param {any} v */ (v) => (store_values[store_name][2] = v) |
| 259 | ); |
| 260 | store_values[store_name][1] = unsub; |
| 261 | return store_values[store_name][2]; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Sets the new value of a store and returns that value. |
no test coverage detected