@@ -306,6 +306,53 @@ const getProps = layout => {
306
306
} ;
307
307
} ;
308
308
309
+ export function setPersistance ( layout , newProps , dispatch ) {
310
+ const {
311
+ canPersist,
312
+ id,
313
+ props,
314
+ element,
315
+ persistence,
316
+ persisted_props,
317
+ persistence_type
318
+ } = getProps ( layout ) ;
319
+
320
+ const getFinal = ( propName , prevVal ) =>
321
+ propName in newProps ? newProps [ propName ] : prevVal ;
322
+ const finalPersistence = getFinal ( 'persistence' , persistence ) ;
323
+
324
+ if ( ! canPersist || ! finalPersistence || finalPersistence !== persistence ) {
325
+ return ;
326
+ }
327
+
328
+ forEach ( persistedProp => {
329
+ const [ propName , propPart ] = persistedProp . split ( '.' ) ;
330
+ if ( newProps [ propName ] !== undefined ) {
331
+ const storage = getStore ( persistence_type , dispatch ) ;
332
+ const { extract} = getTransform ( element , propName , propPart ) ;
333
+
334
+ const valsKey = getValsKey ( id , persistedProp , persistence ) ;
335
+ let originalVal = extract ( props [ propName ] ) ;
336
+ const newVal = extract ( newProps [ propName ] ) ;
337
+
338
+ if ( originalVal !== newVal ) {
339
+ if ( storage . hasItem ( valsKey ) ) {
340
+ originalVal = storage . getItem ( valsKey ) [ 1 ] ;
341
+ if ( newVal !== originalVal ) {
342
+ storage . setItem ( valsKey , [ newVal , originalVal ] , dispatch ) ;
343
+ }
344
+ else {
345
+ storage . removeItem ( valsKey )
346
+ }
347
+ }
348
+ else {
349
+ storage . setItem ( valsKey , [ newVal , originalVal ] , dispatch ) ;
350
+ }
351
+ }
352
+ }
353
+ } , persisted_props ) ;
354
+ }
355
+
309
356
export function recordUiEdit ( layout , newProps , dispatch ) {
310
357
const {
311
358
canPersist,
@@ -517,28 +564,6 @@ export function prunePersistence(layout, newProps, dispatch) {
517
564
filter ( notInNewProps , finalPersistedProps )
518
565
) ;
519
566
}
520
-
521
- // now the main point - clear any edit of a prop that changed
522
- // note that this is independent of the new prop value.
523
- const transforms = element . persistenceTransforms || { } ;
524
- for ( const propName in newProps ) {
525
- const propTransforms = transforms [ propName ] ;
526
- if ( propTransforms ) {
527
- for ( const propPart in propTransforms ) {
528
- finalStorage . removeItem (
529
- getValsKey (
530
- id ,
531
- `${ propName } .${ propPart } ` ,
532
- finalPersistence
533
- )
534
- ) ;
535
- }
536
- } else {
537
- finalStorage . removeItem (
538
- getValsKey ( id , propName , finalPersistence )
539
- ) ;
540
- }
541
- }
542
567
}
543
568
return persistenceChanged ? mergeRight ( newProps , update ) : newProps ;
544
569
}
0 commit comments