-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathView.js
109 lines (96 loc) · 3.04 KB
/
View.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Owner: [email protected]
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2014
*/
define(function(require, exports, module) {
var EventHandler = require('./EventHandler');
var OptionsManager = require('./OptionsManager');
var RenderNode = require('./RenderNode');
/**
* Useful for quickly creating elements within applications
* with large event systems. Consists of a RenderNode paired with
* an input EventHandler and an output EventHandler.
* Meant to be extended by the developer.
*
* @class View
* @uses EventHandler
* @uses OptionsManager
* @uses RenderNode
* @constructor
*/
function View(options) {
this._node = new RenderNode();
this._eventInput = new EventHandler();
this._eventOutput = new EventHandler();
EventHandler.setInputHandler(this, this._eventInput);
EventHandler.setOutputHandler(this, this._eventOutput);
this.options = Object.create(this.constructor.DEFAULT_OPTIONS || View.DEFAULT_OPTIONS);
this._optionsManager = new OptionsManager(this.options);
if (options) this.setOptions(options);
}
View.DEFAULT_OPTIONS = {}; // no defaults
/**
* Look up options value by key
* @method getOptions
*
* @param {string} key key
* @return {Object} associated object
*/
View.prototype.getOptions = function getOptions() {
return this._optionsManager.value();
};
/*
* Set internal options.
* No defaults options are set in View.
*
* @method setOptions
* @param {Object} options
*/
View.prototype.setOptions = function setOptions(options) {
this._optionsManager.patch(options);
};
/**
* Add a child renderable to the view.
* Note: This is meant to be used by an inheriting class
* rather than from outside the prototype chain.
*
* @method add
* @return {RenderNode}
* @protected
*/
View.prototype.add = function add() {
return this._node.add.apply(this._node, arguments);
};
/**
* Alias for add
* @method _add
*/
View.prototype._add = View.prototype.add;
/**
* Generate a render spec from the contents of this component.
*
* @private
* @method render
* @return {number} Render spec for this component
*/
View.prototype.render = function render() {
return this._node.render();
};
/**
* Return size of contained element.
*
* @method getSize
* @return {Array.Number} [width, height]
*/
View.prototype.getSize = function getSize() {
if (this._node && this._node.getSize) {
return this._node.getSize.apply(this._node, arguments) || this.options.size;
}
else return this.options.size;
};
module.exports = View;
});