-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (37 loc) · 1.06 KB
/
index.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
define(function(require) {
'use strict';
var $ = require('jquery');
var Backbone = require('backbone');
var Marionette = require('marionette');
var morphdom = require('morphdom');
var Router = require('router');
var Root = require('root');
var store = require('store');
window.getState = store.getState; // FOR DEMO PURPOSES ONLY
var root = new Root();
var virtualRoot = new Root();
var app;
store.subscribe(function updateDOM() {
var windowDOM = root.$el[0];
var virtualDOM = virtualRoot.render().$el[0];
morphdom(windowDOM, virtualDOM, {
childrenOnly: true,
onBeforeElUpdated: function(fromEl, toEl) {
var newModel = $(toEl).data('model');
if (fromEl.hasAttribute('ref')) {
$(toEl).trigger('before:update', fromEl);
}
if (newModel) {
$(fromEl).data('model', newModel);
}
}
});
});
app = new Marionette.Application();
app.addRegions({
appRegion: '#appRegion'
});
new Router();
Backbone.history.start();
app.appRegion.show(root);
});