forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marionette.d.ts
1377 lines (1155 loc) · 53.9 KB
/
marionette.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Marionette
// Project: https://github.com/marionettejs/
// Definitions by: Zeeshan Hamid <https://github.com/zhamid>, Natan Vivo <https://github.com/nvivo>, Sven Tschui <https://github.com/sventschui>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../backbone/backbone.d.ts" />
// declarations for Backbone.BabySitter and Backbone.Wreqr, different projects but included in MarionetteJS
declare module Backbone {
// Backbone.BabySitter
class ChildViewContainer<TModel extends Backbone.Model> {
constructor(initialViews?: any[]);
add(view: View<TModel>, customIndex?: number): void;
findByModel(model: TModel): View<TModel>;
findByModelCid(modelCid: string): View<TModel>;
findByCustom(index: number): View<TModel>;
findByIndex(index: number): View<TModel>;
findByCid(cid: string): View<TModel>;
remove(view: View<TModel>): void;
call(method: any): void;
apply(method: any, args?: any[]): void;
//mixins from Collection (copied from Backbone's Collection declaration)
all(iterator: (element: View<TModel>, index: number) => boolean, context?: any): boolean;
any(iterator: (element: View<TModel>, index: number) => boolean, context?: any): boolean;
contains(value: any): boolean;
detect(iterator: (item: any) => boolean, context?: any): any;
each(iterator: (element: View<TModel>, index: number, list?: any) => void, context?: any): any;
every(iterator: (element: View<TModel>, index: number) => boolean, context?: any): boolean;
filter(iterator: (element: View<TModel>, index: number) => boolean, context?: any): View<TModel>[];
find(iterator: (element: View<TModel>, index: number) => boolean, context?: any): View<TModel>;
first(): View<TModel>;
forEach(iterator: (element: View<TModel>, index: number, list?: any) => void, context?: any): void;
include(value: any): boolean;
initial(): View<TModel>;
initial(n: number): View<TModel>[];
invoke(methodName: string, args?: any[]): any;
isEmpty(object: any): boolean;
last(): View<TModel>;
last(n: number): View<TModel>[];
lastIndexOf(element: View<TModel>, fromIndex?: number): number;
map<U>(iterator: (element: View<TModel>, index: number, context?: any) => U, context?: any): U[];
pluck(attribute: string): any[];
reject(iterator: (element: View<TModel>, index: number) => boolean, context?: any): View<TModel>[];
rest(): View<TModel>;
rest(n: number): View<TModel>[];
select(iterator: any, context?: any): any[];
some(iterator: (element: View<TModel>, index: number) => boolean, context?: any): boolean;
toArray(): any[];
without(...values: any[]): View<TModel>[];
}
// Backbone.Wreqr
module Wreqr {
module radio {
function channel(channelName: string): Channel;
}
class Channel {
constructor(channelName: string);
vent: Backbone.Wreqr.EventAggregator;
reqres: Backbone.Wreqr.RequestResponse;
commands: Backbone.Wreqr.Commands;
channelName: string;
reset(): Channel;
connectEvents(hash: string, context: any): Channel;
connectCommands(hash: string, context: any): Channel;
connectRequests(hash: string, context: any): Channel;
}
class Handlers extends Backbone.Events {
constructor(options?: any);
options: any;
setHandler(name: string, handler: any, context?: any): void;
hasHandler(name: string): boolean;
getHandler(name: string): Function;
removeHandler(name: string): void;
removeAllHandlers(): void;
}
class CommandStorage {
constructor(options?: any);
getCommands(commandName: string): Commands;
addCommand(commandName: string, args: any): void;
clearCommands(commandName: string): void;
}
class Commands extends Handlers {
constructor(options?: any);
storageType: CommandStorage;
execute(name: string, ...args: any[]): void;
}
class RequestResponse extends Handlers {
constructor(options?: any);
request(...args: any[]): any;
}
class EventAggregator extends Backbone.Events {
constructor(options?: any);
}
}
}
declare module Marionette {
/**
* Retrieve an object's attribute either directly from the object, or
* from the object's this.options, with this.options taking precedence.
*/
function getOption(target: any, optionName: string): any;
/**
* Trigger an event and a corresponding method on the target object.
* All arguments that are passed to the triggerMethod call are passed along
* to both the event and the method, with the exception of the event name not
* being passed to the corresponding method.
*/
function triggerMethod(name: string, ...args: any[]): any;
/**
* Invoke triggerMethod on a specific context.
* This is useful when it's not clear that the object has triggerMethod defined.
*/
function triggerMethodOn(ctx: any, name: string, ...args: any[]): any;
/**
* Monitor a view's state, and after it has been rendered and shown in the DOM,
* trigger a "dom:refresh" event every time it is re-rendered.
*/
function MonitorDOMRefresh(view: Backbone.View<Backbone.Model>): void;
/**
* This method is used to bind a backbone "entity" (collection/model) to methods on a target object.
* @param target An object that must have a listenTo method from the EventBinder object.
* @param entity The entity (Backbone.Model or Backbone.Collection) to bind the events from.
* @param bindings a hash of { "event:name": "eventHandler" } configuration. Multiple handlers can be separated by a space. A function can be supplied instead of a string handler name.
*/
function bindEntityEvents(target: any, entity: any, bindings: any): void;
/**
* This method can be used to unbind callbacks from entities' (collection/model) events. It's the opposite of bindEntityEvents
* @param target An object that must have a listenTo method from the EventBinder object.
* @param entity The entity (Backbone.Model or Backbone.Collection) to bind the events from.
* @param bindings a hash of { "event:name": "eventHandler" } configuration. Multiple handlers can be separated by a space. A function can be supplied instead of a string handler name.
*/
function unbindEntityEvents(target: any, entity: any, bindings: any): void;
class Callbacks {
add(callback: Function, contextOverride: any): void;
run(options: any, context: any): void;
reset(): void;
}
/**
* A base class which other classes can extend from. Object incorporates many
* backbone conventions and utilities like initialize and Backbone.Events.
*/
class Object extends Backbone.Events {
/**
* Initialize is called immediately after the Object has been instantiated,
* and is invoked with the same arguments that the constructor received.
*/
initialize(options?: any): void;
/**
* Retrieve an object's attribute either directly from the object, or from
* the object's this.options, with this.options taking precedence.
* @param optionName the name of the option to retrieve.
*/
getOption(optionName: string): any;
/**
* Objects have a destroy method that unbind the events that are directly
* attached to the instance. Invoking the destroy method will trigger a
* "before:destroy" event and corresponding onBeforeDestroy method call.
* These calls will be passed any arguments destroy was invoked with.
* @param args any arguments to pass to the "before:destory" event and call to
* onBeforeDestroy.
*/
destroy(...args: any[]): void;
}
/**
* A Controller is an object used in the Marionette Router. Controllers are
* where you store your Router's callbacks.
*/
class Controller extends Backbone.Events {
/**
* @param options Options that should be stored in this options. Can be retreived via
* getOption.
*/
constructor(options?: any);
/**
* Handles unbinding all of the events that are directly attached to the
* controller instance, as well as those that are bound using the
* EventBinder from the controller.
*
* Invoking the destroy method will trigger the "before:destroy" and
* "destroy" events and the corresponding onBeforeDestory and onDestroy
* method calls. These calls will be passed any arguments destroy was
* invoked with.
*/
destroy(...args: any[]): void;
/**
* Retrieve an object's attribute either directly from the object, or from
* the object's this.options, with this.options taking precedence.
* @param optionName the name of the option to retrieve.
*/
getOption(optionName: string): any;
triggerMethod(name: string, ...args: any[]): any;
}
interface RegionConstructionOptions {
/**
* Specifies the element for the region to manage. This may be
* a selector string, a raw DOM node reference or a jQuery wrapped
* DOM node.
*/
el?: any;
}
interface RegionShowOptions {
/**
* If you replace the current view with a new view by calling show, by
* default it will automatically destroy the previous view. You can
* prevent this behavior by setting this option to true.
*/
preventDestroy?: boolean;
/**
* If you re-call show with the same view, by default nothing will happen
* because the view is already in the region. You can force the view to be
* re-shown by setting this option to true.
*/
forceShow?: boolean;
/**
* Regions that are attached to the document when you execute show are
* special in that the views that they show will also become attached
* to the document. These regions fire a pair of triggerMethods on all
* of the views that are about to be attached � even the nested ones.
* This can cause a performance issue if you're rendering hundreds or
* thousands of views at once.
* If you think these events might be causing some lag in your app, you
* can selectively turn them off with the triggerBeforeAttach
* and triggerAttach properties.
*/
triggerBeforeAttach?: boolean;
/**
* Regions that are attached to the document when you execute show are
* special in that the views that they show will also become attached
* to the document. These regions fire a pair of triggerMethods on all
* of the views that are about to be attached � even the nested ones.
* This can cause a performance issue if you're rendering hundreds or
* thousands of views at once.
* If you think these events might be causing some lag in your app, you
* can selectively turn them off with the triggerBeforeAttach
* and triggerAttach properties.
*/
triggerAttach?: boolean;
}
/**
* Regions provide consistent methods to manage, show and destroy views in
* your applications and layouts. They use a jQuery selector to show your
* views in the correct place.
*/
class Region extends Marionette.Object {
/**
* Build an instance of a region by passing in a configuration object and
* a default region class to use if none is specified in the config.
* The config object should either be a string as a jQuery DOM selector,
* a Region class directly, or an object literal that specifies a selector,
* a custom regionClass, and any options to be supplied to the region
*/
static buildRegion(regionConfig: any, defaultRegionType: any): Region;
/**
* You can specify an el for the region to manage at the time the region
* is instantiated.
*/
constructor(options?: RegionConstructionOptions);
/**
* Contains the element that this region should manage.
*/
el: any;
/**
* Renders and displays the specified view in this region.
* @param view the view to display.
*/
show<TModel extends Backbone.Model>(view: Backbone.View<TModel>, options?: RegionShowOptions): void;
/**
* Attaches an existing view to a region, without rendering or showing the view,
* and without replacing the HTML content of the region.
*/
attachView<TModel extends Backbone.Model>(view: Backbone.View<TModel>, options?: RegionShowOptions): any;
/**
* Override this method to change how the new view is
* appended to the `$el` that the region is managing
*/
attachHtml<TModel extends Backbone.Model>(view: Backbone.View<TModel>): void;
/**
* A region can be reset at any time. This destroys any existing view
* being displayed, and deletes the cached el. The next time the region
* shows a view, the region's el is queried from the DOM.
*/
reset(): any;
/**
* If you wish to check whether a region has a view, you can use the hasView function. This will return a boolean value depending whether or not the region is showing a view.
*/
hasView(): boolean;
/**
* Empties the current view from the region.
*/
empty(): any;
}
interface RegionDefaults {
/**
* A selector string indicating which element to assign the region two.
*/
selector?: string;
/**
* A selector string, a jQuery object, or an HTML node indicating which element
* the region should use.
*/
el?: any;
/**
* A custom region class.
*/
regionClass?: any;
/**
* Ordinarily regions enforce the presence of a backing DOM element. In
* some instances it may be desirable to allow regions to be instantiated
* and used without an element, such as when regions defined by a parent
* LayoutView class are used by only some of its subclasses. In these
* instances, the region can be defined with this option set to true,
* suppressing the missing element error and causing show calls to the
* region to be treated as no-ops.
*/
allowMissingEl?: boolean;
}
/**
* Region managers provide a consistent way to manage a number of Marionette.Region
* objects within an application. The RegionManager is intended to be used by
* other objects, to facilitate the addition, storage, retrieval, and removal of
* regions from that object.
*/
class RegionManager extends Controller {
/**
* Constructor.
* @param options May contain an optional `regions` option. These regions
* are passed directly into addRegions for this instance.
*/
constructor(options?: any);
/**
* Adds one or more regions to this RegionManager instance.
* @param regionDefinitions a function returning an object literal with the region definitions. The function will
* be called with the RegionManager instance context and all the arguments passed to addRegions.
* @param defaults Specifies default options that will be applied to every region added.
* @returns an object literal with all the created regions.
*/
addRegions(regionDefinitions: Function, defaults?: RegionDefaults): any;
/**
* Adds one or more regions to this RegionManager instance.
* @param regionDefinitions an object literal containing region names as keys and region
* definitions as values.
* @param defaults Specifies default options that will be applied to every region added.
* @returns an object literal with all the created regions.
*/
addRegions(regionDefinitions: { [regionName: string]: any }, defaults?: RegionDefaults): any;
/**
* Adds a region to this RegionManager.
* @param name the region name.
* @param definition the region definition. This may be a selector, object literal
* with various region creation options or an instance of a region object.
*/
addRegion(name: string, definition: any): Region;
/**
* Gets the region with the specified name from this RegionManager.
*/
get(name: string): Region;
/**
* Removes the region with the specified name from this RegionManager.
*/
removeRegion(name: string): void;
/**
* Removes all regions from the RegionManager.
*/
removeRegions(): void;
/**
* Empties all regions from the RegionManager instance.
*/
emptyRegions(): void;
/**
* Destroys the RegionManager instance entierly which both destroys and
* removes all regions from the RegionManager instance.
*/
destroy(): void;
//mixins from Collection (copied from Backbone's Collection declaration)
/**
* Returns true if all of the values in the list pass the predicate truth test.
* @alias every
*/
all(iterator: (element: Region, index: number) => boolean, context?: any): boolean;
/**
* Returns true if any of the values in the list pass the predicate truth test. Short-circuits and stops traversing the list if a true element is found.
*/
any(iterator: (element: Region, index: number) => boolean, context?: any): boolean;
/**
* Returns true if the value is present in the list.
* @alias include
*/
contains(value: any): boolean;
/**
* Looks through each value in the list, returning the first one that passes a truth test (predicate), or undefined if no value passes the test.The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.
* @alias find
*/
detect(iterator: (item: any) => boolean, context?: any): any;
/**
* Iterates over the regions in this instance, yielding each in turn to an
* iterator function. The iterator is bound to the context object, if one
* is passed.
* @alias forEach
*/
each(iterator: (element: Region, index: number, list?: any) => void, context?: any): void;
/**
* Returns true if all of the values in the list pass the predicate truth test.
* @alias all
*/
every(iterator: (element: Region, index: number) => boolean, context?: any): boolean;
/**
* Looks through each Region in the collection, returning an array of all
* the values that pass a truth test (predicate).
* @alias select
*/
filter(iterator: (element: Region, index: number) => boolean, context?: any): Region[];
/**
* Looks through each Region in this instance, returning the first one that passes a truth test (predicate), or undefined if no value passes the test.The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.
* @alias detect
*/
find(iterator: (element: Region, index: number) => boolean, context?: any): Region;
/**
* Returns the first Region of this RegionManager.
*/
first(): Region;
/**
* Returns the first n Regions of this RegionManager.
*/
first(n: number): Region[];
/**
* Iterates over the regions in this instance, yielding each in turn to an
* iterator function. The iterator is bound to the context object, if one
* is passed.
* @alias each
*/
forEach(iterator: (element: Region, index: number, list?: any) => void, context?: any): void;
/**
* Returns true if the value is present in the list.
* @alias contains
*/
include(value: any): boolean;
/**
* Returns everything but the last n Regions of this instance.
* @param n if specified determines the number of regions to exclude,
* otherwise only the last element is excluded.
*/
initial(n: number): Region[];
/**
* Calls the method named by methodName on each value in the collection. Any extra
* arguments passed to invoke will be forwarded on to the method invocation.
*/
invoke(methodName: string, args?: any[]): any;
/**
* Returns true if the RegionManager contains no regions.
*/
isEmpty(object: any): boolean;
/**
* Returns the last element of a collection.
*/
last(): Region;
/**
* Returns the last n elements of the collection.
*/
last(n: number): Region[];
/**
* Returns the index of the last occurrence of element in the collection, or -1 if
* element is not present.
* @param fromIndex if specified starts the search at the given index.
*/
lastIndexOf(element: Region, fromIndex?: number): number;
/**
* Produces a new array of values by mapping each value in the collection through a
* transformation function (iterator).
* @alias collect
*/
map(iterator: (element: Region, index: number, context?: any) => any[], context?: any): any[];
/**
* Pluck an attribute from each model in the collection. Equivalent to
* calling map and returning a single attribute from the iterator.
*/
pluck(attribute: string): any[];
/**
* Returns the values in the collection without the elements that the truth test
* (predicate) passes. The opposite of filter.
*/
reject(iterator: (element: Region, index: number) => boolean, context?: any): Region[];
/**
* Returns the rest of the elements of the collection.
* Pass an index to return the values of the array from that index onward. If not
* specified the first item in the collection is dropped.
* @alias tail, drop
*/
rest(n: number): Region[];
/**
* Looks through each value in the collection, returning an array of all
* the values that pass a truth test (predicate).
* @alias filter
*/
select(iterator: any, context?: any): Region[];
/**
* Returns true if any of the values in the list pass the predicate truth test. Short-circuits and stops traversing the list if a true element is found.
* @alias any
*/
some(iterator: (element: Region, index: number) => boolean, context?: any): boolean;
/**
* Creates an array containing the regions in this instance.
*/
toArray(): Region[];
/**
* Returns an array of all the regions in the RegionManager except the ones specified.
*/
without(...values: any[]): Region[];
}
/**
* The TemplateCache provides a cache for retrieving templates from script blocks
* in your HTML. This will improve the speed of subsequent calls to get a template.
*/
class TemplateCache {
/**
* To use the TemplateCache, call the get method on TemplateCache directly. Internally, instances of the TemplateCache class will be created and stored but you do not have to manually create these instances yourself. get will return a compiled template function.
*/
static get(templateId: string): any;
/**
* You can clear one or more, or all items from the cache using the clear
* method. Clearing a template from the cache will force it to re-load
* from the DOM the next time it is retrieved.
* @param the templateId used for loading / caching of the templates to clear. If none specified, all templates will be cleared from the cache.
*/
static clear(...templateId: string[]): void;
/**
* The default template retrieval is to select the template contents from the
* DOM using jQuery. If you wish to change the way this works, you can
* override this method on the TemplateCache object.
*/
loadTemplate(templateId: string): any;
/**
* he default template compilation passes the results from loadTemplate to
* the compileTemplate function, which returns an underscore.js compiled
* template function. When overriding compileTemplate remember that it
* must return a function which takes an object of parameters and values
* and returns a formatted HTML string.
*/
compileTemplate(rawTemplate: any): any;
}
/**
* The Renderer object was extracted from the ItemView rendering process, in
* order to create a consistent and re-usable method of rendering a template
* with or without data.
*/
class Renderer {
/**
* This method returns a string containing the result of applying the
* template using the data object as the context.
* @param template The template to render. If this is a function this is
* treated as a pre-compiled template and does not try to compile it again. This
* allows any view that supports a template parameter to specify a pre-compiled
* template function as the template setting. The template function does not
* have to be any specific template engine. It only needs to be a function
* that returns valid HTML as a string from the data parameter passed to
* the function.
*/
static render(template: any, data: any): string;
}
/**
* This base view provides some common and core functionality for other views
* to take advantage of.
* Note: The Marionette.View class is not intended to be used directly. It
* exists as a base view for other view classes to be extended from, and to
* provide a common location for behaviors that are shared across all views.
*/
class View<TModel extends Backbone.Model> extends Backbone.View<TModel> {
constructor(options?: Backbone.ViewOptions<TModel>);
/**
* Defines behaviors attached to this view.
*/
behaviors: any;
/**
* Defines `triggers` to forward DOM events to view
* events. `triggers: {"click .foo": "do:foo"}`
*/
triggers:{[key:string]:any};
/**
* A configuration hash for models. The left side is the event on
* the model, and the right side is the name of the
* method on the view or a function to handle the event. This property
* can also be a function that returns the hash described above.
*/
modelEvents: any;
/**
* A configuration hash for collections. The left side is the event on
* the collection, and the right side is the name of the
* method on the view or a function to handle the event. This property
* can also be a function that returns the hash described above.
*/
collectionEvents: any;
/**
* In several cases you need to access ui elements inside the view to
* retrieve their data or manipulate them. For example you have a certain
* div element you need to show/hide based on some state, or other ui
* element that you wish to set a css class to it. Instead of having
* jQuery selectors hanging around in the view's code you can define a
* ui hash that contains a mapping between the ui element's name and its
* jQuery selector. Afterwards you can simply access it via
* this.ui.elementName.
*/
ui: any;
/**
* There may be some cases where you need to change the template that is
* used for a view, based on some simple logic such as the value of a
* specific attribute in the view's model. To do this, you can provide a
* getTemplate function on your views and use this to return the template
* that you need.
*/
getTemplate(): any;
/**
* Retrieve an object's attribute either directly from the object, or
* from the object's this.options, with this.options taking precedence.
*/
getOption<T>(optionName:string): T;
mixinTemplateHelpers(target?: any): any;
configureTriggers(): any;
/**
* View implements a destroy method, which is called by the region managers automatically. As part of the implementation.
*/
destroy(...args: any[]): void;
/**
* In several cases you need to access ui elements inside the view to
* retrieve their data or manipulate them. For example you have a certain
* div element you need to show/hide based on some state, or other ui
* element that you wish to set a css class to it. Instead of having jQuery
* selectors hanging around in the view's code you can define a ui hash
* that contains a mapping between the ui element's name and its jQuery
* selector. Afterwards you can simply access it via this.ui.elementName.
* This functionality is provided via the bindUIElements method.
* Since View doesn't implement the render method, then if you directly
* extend from View you will need to invoke this method from your render
* method. In ItemView and CompositeView this is already taken care of.
*/
bindUIElements(): any;
unbindUIElements(): any;
triggerMethod(name: string, ...args: any[]): any;
/**
* Called on the view instance when the view has been rendered and
* displayed. This event can be used to react to when a view has been
* shown via a region. A common use case for the onShow method is to
* use it to add children views.
*/
onShow(): void;
/**
* Triggered just after the view has been destroyed.
*/
onDestroy(): void;
/**
* When destroying a view, an onBeforeDestroy method will be called, if
* it has been provided, just before the view destroys. It will be passed
* any arguments that destroy was invoked with.
*/
onBeforeDestroy(...args: any[]): void;
/**
* Called anytime that showing the view in a Region causes it to be
* attached to the document.
*/
onAttach(): void;
/**
* Triggered right before the view is attached to the document.
*/
onBeforeAttach(): void;
/**
* Triggered after the view has been rendered, has been shown in the DOM via a Marionette.Region, and has been re-rendered.
* This event / callback is useful for DOM-dependent UI plugins such as jQueryUI or KendoUI.
*/
onDomRefresh(): void;
}
/**
* An ItemView is a view that represents a single item. That item may be
* a Backbone.Model or may be a Backbone.Collection. Whichever it is though,
* it will be treated as a single item.
*/
class ItemView<TModel extends Backbone.Model> extends View<TModel> {
constructor(options?: Backbone.ViewOptions<TModel>);
/**
* Item views will serialize a model or collection, by default, by calling
* .toJSON on either the model or collection. If both a model and
* collection are attached to an item view, the model will be used as the
* data source. The results of the data serialization will be passed to
* the template that is rendered.
*
* If you need custom serialization for your data, you can provide a serializeData
* method on your view. It must return a valid JSON object, as if you had
* called .toJSON on a model or collection.
*/
serializeData(): any;
/**
* Renders the view. It is unwise to override the render method of any
* Marionette view. Instead, you should use the onBeforeRender and
* onRender callbacks to layer in additional functionality to the
* rendering of your view.
*/
render(): ItemView<TModel>;
/**
* Triggered before an ItemView is rendered.
*/
onBeforeRender(): void;
/**
* Triggered after the view has been rendered. You can implement this in
* your view to provide custom code for dealing with the view's el after
* it has been rendered.
*/
onRender(): void;
}
interface CollectionViewOptions<TModel extends Backbone.Model> extends Backbone.ViewOptions<TModel> {
/**
* By default the CollectionView will maintain a sorted collection's order
* in the DOM. This behavior can be disabled by specifying {sort: false}
* on initialize.
*/
sort?: boolean;
}
/**
* The CollectionView will loop through all of the models in the specified
* collection, render each of them using a specified childView, then append
* the results of the child view's el to the collection view's el. By
* default the CollectionView will maintain a sorted collection's order in the
* DOM. This behavior can be disabled by specifying {sort: false} on
* initialize.
*/
class CollectionView<TModel extends Backbone.Model> extends View<TModel> {
constructor(options?: CollectionViewOptions<TModel>);
/**
* Specify a childView in your collection view definition. This must be a
* Backbone view object definition, not an instance. It can be any
* Backbone.View or be derived from Marionette.ItemView
*/
childView: any;
/**
* There may be scenarios where you need to pass data from your parent
* collection view in to each of the childView instances. To do this,
* provide a childViewOptions definition on your collection view as an
* object literal. This will be passed to the constructor of your childView
* as part of the options.
*
* You can also specify the childViewOptions as a function, if you need to
* calculate the values to return at runtime. The model will be passed
* into the function should you need access to it when calculating
* childViewOptions. The function must return an object, and the attributes of
* the object will be copied to the childView instance's options.
*/
childViewOptions: any;
/**
* You can customize the event prefix for events that are forwarded through
* the collection view. To do this, set the childViewEventPrefix on the
* collection view.
*/
childViewEventPrefix: string;
/**
* You can specify a childEvents hash or method which allows you to
* capture all bubbling childEvents without having to manually set bindings.
* The keys of the hash can either be a function or a string that is the
* name of a method on the collection view.
*/
childEvents: any;
/**
* When a collection has no children, and you need to render a view other than
* the list of childViews, you can specify an emptyView attribute on your collection
* view.
*/
emptyView: any;
/**
* Similar to childView and childViewOptions, there is an emptyViewOptions
* property that will be passed to the emptyView constructor. It can be
* provided as an object literal or as a function. If emptyViewOptions
* aren't provided the CollectionView will default to passing the
* childViewOptions to the emptyView.
*/
emptyViewOptions: any;
/**
* The CollectionView uses Backbone.BabySitter to store and manage its
* child views. This allows you to easily access the views within the
* collection view, iterate them, find them by a given indexer such as the
* view's model or collection, and more.
*/
children: Backbone.ChildViewContainer<TModel>;
/**
* The render method of the collection view is responsible for rendering the
* entire collection. It loops through each of the children in the collection
* and renders them individually as an childView.
*/
render(): CollectionView<TModel>;
/**
* The addChild method is responsible for rendering the childViews and
* adding them to the HTML for the collectionView instance. It is also
* responsible for triggering the events per ChildView. In most cases you
* should not override this method.
*/
addChild(item: any, ChildView: Backbone.View<TModel>, index: Number): void;
renderChildView(view: Backbone.View<TModel>, index: Number): void;
/**
* When a custom view instance needs to be created for the childView that
* represents a child, override the buildChildView method. This method
* takes three parameters and returns a view instance to be used as the
* child view.
*/
buildChildView(child: any, ItemViewType: any, itemViewOptions: any): View<TModel>;
/**
* Remove the child view and destroy it. This function also updates the indices of
* later views in the collection in order to keep the children in sync with the collection.
*/
removeChildView(view: any): void;
/**
* Determines if the view is empty. If you want to control when the empty
* view is rendered, you can override isEmpty.
*/
isEmpty(): boolean;
/**
* If empty, show the empty view
*/
checkEmpty(): void;
destroyChildren(): void;
/**
* By default the CollectionView will maintain the order of its collection
* in the DOM. However on occasions the view may need to re-render to make
* this possible, for example if you were to change the comparator on the
* collection. By default CollectionView will call render when this happens,
* but there are cases where this may not be suitable. For instance when
* sorting the children in a CompositeView, you want to only render the
* internal collection.
*/
resortView(): void;
/**
* By default the collection view will append the HTML of each ChildView
* into the element buffer, and then call jQuery's .append once at the end
* to move the HTML into the collection view's el.
* You can override this by specifying an attachHtml method in your view
* definition.
* @param collectionView the instance of the collection view that will receive the HTML.
* @param childView the current child view instance.
* @param index he index of the model that this childView instance represents,
* in the collection that the model came from. This is useful for sorting
* a collection and displaying the sorted list in the correct order on the
* screen.
*/
attachHtml(collectionView: CollectionView<TModel>, childView: Backbone.View<TModel>, index: number): void;
/**
* The value returned by this method is the ChildView class that will be
* instantiated when a Model needs to be initially rendered. This method
* also gives you the ability to customize per Model ChildViews.
*/
getChildView(item: TModel): any;
/**