(layout, newProps, dispatch)
| 310 | }; |
| 311 | |
| 312 | export function recordUiEdit(layout, newProps, dispatch) { |
| 313 | const { |
| 314 | canPersist, |
| 315 | id, |
| 316 | props, |
| 317 | element, |
| 318 | persistence, |
| 319 | persisted_props, |
| 320 | persistence_type |
| 321 | } = getProps(layout); |
| 322 | |
| 323 | // if the "persistence" property is changed as a callback output, |
| 324 | // skip the persistence storage overwriting. |
| 325 | const isPersistenceMismatch = |
| 326 | newProps?.persistence !== undefined && |
| 327 | newProps.persistence !== persistence; |
| 328 | |
| 329 | if (!canPersist || !persistence || isPersistenceMismatch) { |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | forEach(persistedProp => { |
| 334 | const [propName, propPart] = persistedProp.split('.'); |
| 335 | if (newProps[propName] !== undefined) { |
| 336 | const storage = getStore(persistence_type, dispatch); |
| 337 | const {extract} = getTransform(element, propName, propPart); |
| 338 | |
| 339 | const valsKey = getValsKey(id, persistedProp, persistence); |
| 340 | let originalVal = extract(props[propName]); |
| 341 | const newVal = extract(newProps[propName]); |
| 342 | |
| 343 | // mainly for nested props with multiple persisted parts, it's |
| 344 | // possible to have the same value as before - should not store |
| 345 | // in this case. |
| 346 | if (originalVal !== newVal) { |
| 347 | if (storage.hasItem(valsKey)) { |
| 348 | originalVal = storage.getItem(valsKey)[1]; |
| 349 | } |
| 350 | const vals = |
| 351 | originalVal === undefined |
| 352 | ? [newVal] |
| 353 | : [newVal, originalVal]; |
| 354 | storage.setItem(valsKey, vals, dispatch); |
| 355 | } |
| 356 | } |
| 357 | }, persisted_props); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Used for entire layouts (on load) or partial layouts (from children |
no test coverage detected
searching dependent graphs…