forked from rickekelschot/backbone.supercharger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (64 loc) · 2.32 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Settings test</title>
</head>
<body>
<div class="test" style="display: block; height: 100px; width: 100px; background: red"></div>
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/backbone/backbone.js"></script>
<script src="dist/backbone-patterns.js"></script>
<script>
(function () {
var View = Backbone.View.extend({
optionNames: ['test'],
subscriptions: {
'globalTest': 'handleGlobalTest',
'custom': {
'customTest': 'handleCustomTest'
}
},
initialize: function () {
this.reply('log', function (a, b) {
return 'hello ' + a + ' ' + b;
});
this.reply('default', function (a, b) {
console.log('caught ' + a + ' ' + b);
});
this.channel('custom').reply('log', function (a, b) {
return 'world ' + a + ' ' + b;
})
this.comply('jump', function () {
console.log('I jumped');
});
},
handleGlobalTest: function (request) {
console.log(this.request(request, 'world', Math.random()));
},
handleCustomTest: function (request) {
console.log(this.channel('custom').request(request, 'hello', Math.random()));
}
});
var view = new View({
el: '.test',
test: 'lala'
});
Backbone.mediator.publish('globalTest', 'log');
Backbone.mediator.channel('custom').publish('customTest', 'log');
Backbone.mediator.command('jump');
Backbone.mediator.request('someUnhandledRequest', 'test');
view.remove();
var model = new Backbone.Model();
model.url = 'https://api.github.com/repos/vmg/redcarpet/issues';
model.fetch();
model.abort();
var collection = new Backbone.Collection();
collection.url = 'https://api.github.com/repos/vmg/redcarpet/issues';
collection.fetch();
collection.abort();
})();
</script>
</body>
</html>