1
+ // Type definitions for Backbone-associations 0.6.4
2
+ // Project: https://github.com/dhruvaray/backbone-associations/
3
+ // Definitions by: Craig Brett <https://github.com/craigbrett17/>
4
+ // Definitions: https://github.com/borisyankov/DefinitelyTyped
5
+
6
+ /// <reference path="../backbone/backbone.d.ts" />
7
+
8
+ declare module Backbone {
9
+ export module Associations {
10
+ /** Defines a 1:Many relationship type */
11
+ export var Many : string ;
12
+ /** Defines a 1:1 relationship type */
13
+ export var One : string ;
14
+ /** Defines a special relationship to itself */
15
+ export var Self : string ;
16
+
17
+ // these seem to be used internally, but can't see a reason not to include them just in case
18
+ export var SEPARATOR : string ;
19
+ export function getSeparator ( ) : any ;
20
+ export function setSeparator ( value : any ) : void ;
21
+ export var EVENTS_BUBBLE : boolean ;
22
+ export var EVENTS_WILDCARD : boolean ;
23
+ export var EVENTS_NC : boolean ;
24
+
25
+ interface IRelation {
26
+ /** The type of model for this relationship */
27
+ relatedModel : string | typeof Backbone . Associations . AssociatedModel ;
28
+ /** The key for this relationship on this model */
29
+ key : string ;
30
+ // meh, no string enums in TS. Just have to trust the user not to be a fool
31
+ /** The cardinality of this relationship. */
32
+ type : string ;
33
+ /** Determines the type of collection used. If used, the relatedModel property is ignored */
34
+ collectionType ?: typeof Backbone . Collection | string ;
35
+ /** If set to true, then the attribute will not be serialized in toJSON() calls. Defaults to false */
36
+ isTransient ?: boolean ;
37
+ /** Specify remoteKey to serialize the key to a different key name in toJSON() calls. Useful in ROR nested-attributes like scenarios. */
38
+ remoteKey ?: string ;
39
+ /** the attributes to serialize when calling toJSON */
40
+ serialize ?: string [ ] ;
41
+ /** A transformation function to convert the value before it is assigned to the key on the relatedModel */
42
+ map ?: ( ...args : any [ ] ) => any ;
43
+ }
44
+
45
+ /** A Backbone model with special provision for handling relations to other models */
46
+ export class AssociatedModel extends Backbone . Model {
47
+ /** Relations with their associated model */
48
+ relations : IRelation [ ] ;
49
+ _proxyCalls : any ;
50
+ /** Reverse association lookup for objects that contain this object */
51
+ parents : any [ ] ;
52
+ /** Cleans up any parent relations on other AssociatedModels */
53
+ cleanup ( ) : void ;
54
+ }
55
+ }
56
+ // copies of properties also put onto the Backbone scope
57
+ /** Defines a 1:Many relationship type */
58
+ export var Many : string ;
59
+ /** Defines a 1:1 relationship type */
60
+ export var One : string ;
61
+ /** Defines a special relationship to itself */
62
+ export var Self : string ;
63
+
64
+ // I'm sure this should be doable with imports or type aliases, but doesn't seem to work
65
+ /** A Backbone model with special provision for handling relations to other models */
66
+ export class AssociatedModel extends Backbone . Model {
67
+ /** Relations with their associated model */
68
+ relations : Associations . IRelation [ ] ;
69
+ _proxyCalls : any ;
70
+ /** Reverse association lookup for objects that contain this object */
71
+ parents : any [ ] ;
72
+ /** Cleans up any parent relations on other AssociatedModels */
73
+ cleanup ( ) : void ;
74
+ }
75
+ }
0 commit comments