File tree Expand file tree Collapse file tree
desktop/src/@batch-flask/core/record Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,13 +56,12 @@ export function ListProp<T>(type: any) {
5656 } ;
5757}
5858
59- export function Model ( ) {
59+ export function Model ( name ?: string ) {
6060 return < T extends new ( ...args : any [ ] ) => { } > ( ctr : T ) => {
6161 if ( ! ( ctr . prototype instanceof Record ) ) {
6262 throw new RecordMissingExtendsError ( ctr ) ;
6363 }
64-
65- return ( class extends ctr {
64+ const model = ( class extends ctr {
6665 constructor ( ...args : any [ ] ) {
6766 const [ data ] = args ;
6867 if ( data instanceof ctr ) {
@@ -72,5 +71,7 @@ export function Model() {
7271 ( this as any ) . _completeInitialization ( ) ;
7372 }
7473 } ) ;
74+ Object . defineProperty ( model , "name" , { value : name || ctr . name } ) ;
75+ return model ;
7576 } ;
7677}
Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ class InheritedTestRec extends SimpleTestRec {
4444 public d : number ;
4545}
4646
47+ @Model ( "CustomName" )
48+ class CustomNameRec extends Record < any > {
49+ @Prop ( )
50+ public id : string = "default-id" ;
51+ }
52+
4753describe ( "Record" , ( ) => {
4854 it ( "should throw an exeption when record doesn't extends Record class" , ( ) => {
4955 try {
@@ -176,4 +182,12 @@ describe("Record", () => {
176182 expect ( SimpleTestRec . isStaticMethod ) . not . toBeFalsy ( ) ;
177183 expect ( SimpleTestRec . isStaticMethod ( ) ) . toBe ( true ) ;
178184 } ) ;
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+ } ) ;
179193} ) ;
You can’t perform that action at this time.
0 commit comments