1 |
|
2 | (function() {
|
3 | var defineModule, each, isPlainObject, log, lowerCamelCase, object, ref, upperCamelCase,
|
4 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
5 | hasProp = {}.hasOwnProperty;
|
6 |
|
7 | ref = require('art-standard-lib'), defineModule = ref.defineModule, log = ref.log, object = ref.object, upperCamelCase = ref.upperCamelCase, lowerCamelCase = ref.lowerCamelCase, each = ref.each, isPlainObject = ref.isPlainObject;
|
8 |
|
9 | defineModule(module, function() {
|
10 | return function(superClass) {
|
11 | var DeclarableMixin;
|
12 | return DeclarableMixin = (function(superClass1) {
|
13 | extend(DeclarableMixin, superClass1);
|
14 |
|
15 | function DeclarableMixin() {
|
16 | return DeclarableMixin.__super__.constructor.apply(this, arguments);
|
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 | DeclarableMixin.declarable = function(map) {
|
50 | return each(map, (function(_this) {
|
51 | return function(options, name) {
|
52 | var extendable, getter, getterName, internalName, obj, preprocess, ucProp, validate;
|
53 | if (isPlainObject(options)) {
|
54 | preprocess = options.preprocess, validate = options.validate, extendable = options.extendable, getter = options.getter;
|
55 | }
|
56 | preprocess || (preprocess = function(v) {
|
57 | return v;
|
58 | });
|
59 | validate || (validate = function() {
|
60 | return true;
|
61 | });
|
62 | name = lowerCamelCase(name);
|
63 | ucProp = upperCamelCase(name);
|
64 | internalName = _this.propInternalName(name);
|
65 | getterName = "get" + ucProp;
|
66 | if (extendable) {
|
67 | return _this.extendableProperty((
|
68 | obj = {},
|
69 | obj["" + name] = extendable,
|
70 | obj
|
71 | ));
|
72 | } else {
|
73 | _this[name] = function(value) {
|
74 | if (!validate(value)) {
|
75 | throw new Error("invalid value: " + (formattedInspect({
|
76 | value: value,
|
77 | name: name
|
78 | })));
|
79 | }
|
80 | return this[internalName] = preprocess(value);
|
81 | };
|
82 | _this[getterName] = getter || function() {
|
83 | return this[internalName];
|
84 | };
|
85 | return _this.addGetter(name, function() {
|
86 | return this["class"][internalName];
|
87 | });
|
88 | }
|
89 | };
|
90 | })(this));
|
91 | };
|
92 |
|
93 | return DeclarableMixin;
|
94 |
|
95 | })(superClass);
|
96 | };
|
97 | });
|
98 |
|
99 | }).call(this);
|
100 |
|
101 |
|