File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ declare namespace schema {
2
2
export type StrategyFunction < T > = ( value : any , parent : any , key : string ) => T ;
3
3
export type SchemaFunction = ( value : any , parent : any , key : string ) => string ;
4
4
export type MergeFunction = ( entityA : any , entityB : any ) => any ;
5
+ export type FallbackFunction < T > = ( key : string , schema : schema . Entity < T > ) => T ;
5
6
6
7
export class Array < T = any > {
7
8
constructor ( definition : Schema < T > , schemaAttribute ?: string | SchemaFunction )
@@ -12,6 +13,7 @@ declare namespace schema {
12
13
idAttribute ?: string | SchemaFunction
13
14
mergeStrategy ?: MergeFunction
14
15
processStrategy ?: StrategyFunction < T >
16
+ fallbackStrategy ?: FallbackFunction < T >
15
17
}
16
18
17
19
export class Entity < T = any > {
Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ type Tweet = {
14
14
const data = {
15
15
/* ...*/
16
16
} ;
17
- const user = new schema . Entity ( 'users' , { } , { idAttribute : 'id_str' } ) ;
17
+ const user = new schema . Entity < User > (
18
+ 'users' ,
19
+ { } ,
20
+ { idAttribute : 'id_str' , fallbackStrategy : ( key ) => ( { id_str : key , name : 'Unknown' } ) }
21
+ ) ;
18
22
const tweet = new schema . Entity (
19
23
'tweets' ,
20
24
{ user : user } ,
You can’t perform that action at this time.
0 commit comments