This repository was archived by the owner on Feb 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-23
lines changed
studio/src/app/utils/editor Expand file tree Collapse file tree 2 files changed +12
-23
lines changed Original file line number Diff line number Diff line change 11export class FirestoreUtils {
2- static filterDelete < T > ( obj : T ) : T {
2+ static filterDelete < T > ( obj : T , replaceWithNull : boolean = false ) : T {
33 if ( typeof obj !== 'object' || Array . isArray ( obj ) ) {
44 return obj ;
55 }
@@ -13,6 +13,8 @@ export class FirestoreUtils {
1313 // We don't want to keep empty leaf {}
1414 if ( Object . keys ( value ) . length > 0 ) {
1515 res [ key ] = value ;
16+ } else if ( replaceWithNull ) {
17+ res [ key ] = null ;
1618 }
1719 } else {
1820 res [ key ] = value ;
Original file line number Diff line number Diff line change @@ -6,31 +6,18 @@ import {DeckAttributes} from '../../models/data/deck';
66import { FirestoreUtils } from './firestore.utils' ;
77
88export class OfflineUtils {
9- static cleanAttributes ( attributes : SlideAttributes | DeckAttributes ) : Promise < SlideAttributes | DeckAttributes > {
10- return new Promise < SlideAttributes | DeckAttributes > ( ( resolve ) => {
11- if ( ! attributes || attributes === undefined ) {
12- resolve ( null ) ;
13- return ;
14- }
9+ static async cleanAttributes ( attributes : SlideAttributes | DeckAttributes ) : Promise < SlideAttributes | DeckAttributes > {
10+ if ( ! attributes || attributes === undefined ) {
11+ return null ;
12+ }
1513
16- const keys : string [ ] = Object . keys ( attributes ) ;
14+ const keys : string [ ] = Object . keys ( attributes ) ;
1715
18- if ( ! keys || keys . length <= 0 ) {
19- resolve ( null ) ;
20- return ;
21- }
16+ if ( ! keys || keys . length <= 0 ) {
17+ return null ;
18+ }
2219
23- keys . forEach ( ( key : string ) => {
24- const attr = attributes [ key ] ;
25-
26- // Replace Firestore "to delete fields" with null values
27- if ( FirestoreUtils . shouldAttributeBeCleaned ( attr ) ) {
28- attributes [ key ] = null ;
29- }
30- } ) ;
31-
32- resolve ( attributes ) ;
33- } ) ;
20+ return FirestoreUtils . filterDelete ( attributes , true ) ;
3421 }
3522
3623 static prepareAttributes ( attributes : SlideAttributes | DeckAttributes ) : Promise < SlideAttributes | DeckAttributes > {
You can’t perform that action at this time.
0 commit comments