File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
desktop/src/@batch-flask/core/record Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -56,13 +56,12 @@ export function ListProp<T>(type: any) {
56
56
} ;
57
57
}
58
58
59
- export function Model ( ) {
59
+ export function Model ( name ?: string ) {
60
60
return < T extends new ( ...args : any [ ] ) => { } > ( ctr : T ) => {
61
61
if ( ! ( ctr . prototype instanceof Record ) ) {
62
62
throw new RecordMissingExtendsError ( ctr ) ;
63
63
}
64
-
65
- return ( class extends ctr {
64
+ const model = ( class extends ctr {
66
65
constructor ( ...args : any [ ] ) {
67
66
const [ data ] = args ;
68
67
if ( data instanceof ctr ) {
@@ -72,5 +71,7 @@ export function Model() {
72
71
( this as any ) . _completeInitialization ( ) ;
73
72
}
74
73
} ) ;
74
+ Object . defineProperty ( model , "name" , { value : name || ctr . name } ) ;
75
+ return model ;
75
76
} ;
76
77
}
Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ class InheritedTestRec extends SimpleTestRec {
44
44
public d : number ;
45
45
}
46
46
47
+ @Model ( "CustomName" )
48
+ class CustomNameRec extends Record < any > {
49
+ @Prop ( )
50
+ public id : string = "default-id" ;
51
+ }
52
+
47
53
describe ( "Record" , ( ) => {
48
54
it ( "should throw an exeption when record doesn't extends Record class" , ( ) => {
49
55
try {
@@ -176,4 +182,12 @@ describe("Record", () => {
176
182
expect ( SimpleTestRec . isStaticMethod ) . not . toBeFalsy ( ) ;
177
183
expect ( SimpleTestRec . isStaticMethod ( ) ) . toBe ( true ) ;
178
184
} ) ;
185
+
186
+ it ( "should allow a custom record name to be set" , ( ) => {
187
+ const rec1 = new TestRec ( ) ;
188
+ expect ( rec1 . constructor . name ) . toEqual ( "TestRec" ) ;
189
+
190
+ const rec2 = new CustomNameRec ( ) ;
191
+ expect ( rec2 . constructor . name ) . toEqual ( "CustomName" ) ;
192
+ } ) ;
179
193
} ) ;
You can’t perform that action at this time.
0 commit comments