-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofio.model.js
40 lines (33 loc) · 1.05 KB
/
ofio.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
define(['ofio/ofio', 'vendor/underscore', 'ofio/ofio.id', 'ofio/ofio.events'], function (Ofio) {
var module = new Ofio.Module({
name: 'ofio.model',
dependencies: arguments
});
module.init = function () {
init_attributes.call(this);
};
module.create_attribute = function (attr, value) {
if (value === undefined) value = null;
Object.defineProperty(this, attr, {
set: function (v) {
if (v !== value) {
value = v;
this.emit('change:' + attr);
this.emit('change');
}
},
get: function () {
return value;
}
})
};
var init_attributes = function () {
var attributes = Object.create(this);
this.attributes.call(attributes);
_.extend(attributes, this.options);
Object.keys(attributes).forEach(function (attr) {
this.create_attribute(attr, attributes[attr]);
}, this);
};
return module;
});