-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.js
78 lines (58 loc) · 1.53 KB
/
model.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
define(function (require) {
'use strict';
var Backbone = require('backbone');
var _ = require('underscore');
var eventBrokerMixin = require('./event-broker');
var listenerMixin = require('./listener');
var Model = Backbone.Model.extend({
constructor: function () {
Backbone.Model.apply(this, arguments);
// Декларативные слушатели
this.delegateListeners();
},
unary: function (name, operation) {
var value = this.get(name);
this.set(name, operation(value));
},
toggleAttr: function (name) {
this.unary(name, function (value) {
return !value;
});
},
inc: function (name) {
this.unary(name, function (value) {
return value + 1;
});
},
dec: function (name) {
this.unary(name, function (value) {
return value - 1;
});
},
dispose: function () {
// todo: Закончить
return;
if (this.disposed) return;
// Finished.
this.disposed = true;
// Unbind all global event handlers.
this.unsubscribeAllEvents();
// Unbind all referenced handlers.
this.stopListening();
// Remove all event handlers on this module.
this.off();
// Remove the collection reference, internal attribute hashes
// and event handlers.
var properties = [
'collection',
'attributes', 'changed',
'_escapedAttributes', '_previousAttributes',
'_silent', '_pending',
'_callbacks'
];
// delete this[prop] for prop in properties
}
});
_.extend(Model.prototype, eventBrokerMixin, listenerMixin);
return Model;
});