-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.js
86 lines (79 loc) · 2.74 KB
/
Example.js
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
define(function (require) {
'use strict';
// Require the application.
var App = require('application');
// The Hub.
var Hub = require('libs/hub');
// And the view(s).
var ExampleView = require('apps/Example/views/ExampleView');
<% if (i18n) { %>
// Locales of the subApp
var en = require('json!apps/Example/locales/en.json');
var fr = require('json!apps/Example/locales/fr.json');
var i18n = require('libs/i18n');
//Register locales
i18n.addLocales('en', en);
i18n.addLocales('fr', fr);
<% } %>
// Declare the new module, and attach it to the solution.
App.module('Example', {
startWithParent: false,
define: function (Example, App, Backbone, Marionette, $, _) {
// Define the controller which will respond to the router.
Example.Controller = Marionette.Controller.extend({
index: function (args) {
if (Example.view) {
Example.view.destroy();
}
Example.view = new ExampleView.View();
// Show the view.
Hub.command('show', Example.view);
},
changeLang: function () {
if (Example.view) {
Example.view.render();
}
},
example: function (args) {
if (Example.view) {
Example.view.destroy();
}
Example.view = new ExampleView.ExampleView();
// Show the view.
Hub.command('show', Example.view);
}
});
// Define the initializer.
Example.addInitializer(function (args) {
// The controller.
Example.controller = new Example.Controller();
<% if (i18n) { %>
// Listent to lang changes
Hub.on('change:lang', this.controller.changeLang);
<% } %>
});
// When our subApp closes, we clean.
Example.addFinalizer(function () {
if (Example.controller) {
Example.controller.destroy();
delete Example.controller;
}
if (Example.view) {
Example.view.destroy();
delete Example.view;
}
});
}
});
// Routes.
App.Example.routes = [{
'': 'index'
}, {
'example': 'example'
}];
//Register our new subApp once the App is ready.
App.ready.done(function () {
Hub.command('createSubApp', App.Example);
});
return App.Example;
});