(source, value, updated_during_traversal = null)
| 179 | * @returns {V} |
| 180 | */ |
| 181 | export function internal_set(source, value, updated_during_traversal = null) { |
| 182 | if (!source.equals(value)) { |
| 183 | old_values.set(source, is_destroying_effect ? value : source.v); |
| 184 | |
| 185 | var batch = Batch.ensure(); |
| 186 | batch.capture(source, value); |
| 187 | |
| 188 | if (DEV) { |
| 189 | if (tracing_mode_flag || active_effect !== null) { |
| 190 | source.updated ??= new Map(); |
| 191 | |
| 192 | // For performance reasons, when not using $inspect.trace, we only start collecting stack traces |
| 193 | // after the same source has been updated more than 5 times in the same flush cycle. |
| 194 | const count = (source.updated.get('')?.count ?? 0) + 1; |
| 195 | source.updated.set('', { error: /** @type {any} */ (null), count }); |
| 196 | |
| 197 | if (tracing_mode_flag || count > 5) { |
| 198 | const error = get_error('updated at'); |
| 199 | |
| 200 | if (error !== null) { |
| 201 | let entry = source.updated.get(error.stack); |
| 202 | |
| 203 | if (!entry) { |
| 204 | entry = { error, count: 0 }; |
| 205 | source.updated.set(error.stack, entry); |
| 206 | } |
| 207 | |
| 208 | entry.count++; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (active_effect !== null) { |
| 214 | source.set_during_effect = true; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if ((source.f & DERIVED) !== 0) { |
| 219 | const derived = /** @type {Derived} */ (source); |
| 220 | |
| 221 | // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies |
| 222 | if ((source.f & DIRTY) !== 0) { |
| 223 | execute_derived(derived); |
| 224 | } |
| 225 | |
| 226 | // During time traveling we don't want to reset the status so that |
| 227 | // traversal of the graph in the other batches still happens |
| 228 | if (batch_values === null) { |
| 229 | update_derived_status(derived); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | source.wv = increment_write_version(); |
| 234 | |
| 235 | // For debugging, in case you want to know which reactions are being scheduled: |
| 236 | // log_reactions(source); |
| 237 | mark_reactions(source, DIRTY, updated_during_traversal); |
| 238 |
no test coverage detected