@@ -8,12 +8,22 @@ import { objectAssign } from '../utils/lang/objectAssign';
88 */
99export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
1010
11- abstract addSplit ( name : string , split : ISplit ) : Promise < boolean >
12- abstract addSplits ( entries : [ string , ISplit ] [ ] ) : Promise < boolean [ ] | void >
13- abstract removeSplits ( names : string [ ] ) : Promise < boolean [ ] | void >
11+ protected abstract addSplit ( split : ISplit ) : Promise < boolean >
12+ protected abstract removeSplit ( name : string ) : Promise < boolean >
13+ protected abstract setChangeNumber ( changeNumber : number ) : Promise < boolean | void >
14+
15+ update ( toAdd : ISplit [ ] , toRemove : ISplit [ ] , changeNumber : number ) : Promise < boolean > {
16+ return Promise . all ( [
17+ this . setChangeNumber ( changeNumber ) ,
18+ Promise . all ( toAdd . map ( addedFF => this . addSplit ( addedFF ) ) ) ,
19+ Promise . all ( toRemove . map ( removedFF => this . removeSplit ( removedFF . name ) ) )
20+ ] ) . then ( ( [ , added , removed ] ) => {
21+ return added . some ( result => result ) || removed . some ( result => result ) ;
22+ } ) ;
23+ }
24+
1425 abstract getSplit ( name : string ) : Promise < ISplit | null >
1526 abstract getSplits ( names : string [ ] ) : Promise < Record < string , ISplit | null > >
16- abstract setChangeNumber ( changeNumber : number ) : Promise < boolean | void >
1727 abstract getChangeNumber ( ) : Promise < number >
1828 abstract getAll ( ) : Promise < ISplit [ ] >
1929 abstract getSplitNames ( ) : Promise < string [ ] >
@@ -52,7 +62,7 @@ export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
5262 newSplit . defaultTreatment = defaultTreatment ;
5363 newSplit . changeNumber = changeNumber ;
5464
55- return this . addSplit ( name , newSplit ) ;
65+ return this . addSplit ( newSplit ) ;
5666 }
5767 return false ;
5868 } ) . catch ( ( ) => false ) ;
0 commit comments