@@ -165,6 +165,7 @@ export class SpraypaintBase {
165
165
static clientApplication : string | null = null
166
166
167
167
static attributeList : Record < string , Attribute > = { }
168
+ static linkList : Array < string > = [ ]
168
169
static extendOptions : any
169
170
static parentClass : typeof SpraypaintBase
170
171
static currentClass : typeof SpraypaintBase = SpraypaintBase
@@ -245,6 +246,7 @@ export class SpraypaintBase {
245
246
subclass . currentClass = subclass
246
247
subclass . prototype . klass = subclass
247
248
subclass . attributeList = cloneDeep ( subclass . attributeList )
249
+ subclass . linkList = cloneDeep ( subclass . linkList )
248
250
}
249
251
250
252
static setAsBase ( ) : void {
@@ -369,6 +371,7 @@ export class SpraypaintBase {
369
371
}
370
372
371
373
Subclass . attributeList = Object . assign ( { } , Subclass . attributeList , attrs )
374
+ Subclass . linkList = Subclass . linkList . slice ( )
372
375
373
376
applyModelConfig ( Subclass , options . static || { } )
374
377
@@ -407,13 +410,17 @@ export class SpraypaintBase {
407
410
> = { }
408
411
@nonenumerable private _attributes ! : ModelRecord < this>
409
412
@nonenumerable private _originalAttributes : ModelRecord < this>
413
+ @nonenumerable private _links ! : ModelRecord < this>
414
+ @nonenumerable private _originalLinks ! : ModelRecord < this>
410
415
@nonenumerable private __meta__ : any
411
416
@nonenumerable private _errors : ValidationErrors < this> = { }
412
417
413
418
constructor ( attrs ?: Record < string , any > ) {
414
419
this . _initializeAttributes ( )
420
+ this . _initializeLinks ( )
415
421
this . assignAttributes ( attrs )
416
422
this . _originalAttributes = cloneDeep ( this . _attributes )
423
+ this . _originalLinks = cloneDeep ( this . _links )
417
424
this . _originalRelationships = this . relationshipResourceIdentifiers (
418
425
Object . keys ( this . relationships )
419
426
)
@@ -424,6 +431,10 @@ export class SpraypaintBase {
424
431
this . _copyPrototypeDescriptors ( )
425
432
}
426
433
434
+ private _initializeLinks ( ) {
435
+ this . _links = { }
436
+ }
437
+
427
438
/*
428
439
* VueJS, along with a few other frameworks rely on objects being "reactive". In practice, this
429
440
* means that when passing an object into an context where you would need change detection, vue
@@ -672,6 +683,7 @@ export class SpraypaintBase {
672
683
cloned . isMarkedForDestruction = this . isMarkedForDestruction
673
684
cloned . isMarkedForDisassociation = this . isMarkedForDisassociation
674
685
cloned . errors = Object . assign ( { } , this . errors )
686
+ cloned . links = Object . assign ( { } , this . links )
675
687
return cloned
676
688
}
677
689
@@ -967,6 +979,25 @@ export class SpraypaintBase {
967
979
Object . keys ( includeDirective )
968
980
)
969
981
}
982
+
983
+ get links ( ) : Record < string , any > {
984
+ return this . _links
985
+ }
986
+
987
+ set links ( links : Record < string , any > ) {
988
+ this . _links = { }
989
+ this . assignLinks ( links )
990
+ }
991
+
992
+ assignLinks ( links ?: Record < string , any > ) : void {
993
+ if ( ! links ) return
994
+ for ( const key in links ) {
995
+ const attributeName = this . klass . deserializeKey ( key )
996
+ if ( this . klass . linkList . indexOf ( attributeName ) > - 1 ) {
997
+ this . _links [ attributeName ] = links [ key ]
998
+ }
999
+ }
1000
+ }
970
1001
}
971
1002
972
1003
; ( < any > SpraypaintBase . prototype ) . klass = SpraypaintBase
0 commit comments