-
Notifications
You must be signed in to change notification settings - Fork 1
/
component.js
77 lines (69 loc) · 1.88 KB
/
component.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
/**
* @license MIT http://troopjs.mit-license.org/
*/
define([
"troopjs-dom/component",
"./config",
"./weave",
"./unweave",
"./woven"
], function (Component, config, weave, unweave, woven) {
"use strict";
/**
* @class widget.component
* @extend dom.component
* @alias feature.component
* @mixin widget.config
* @localdoc Adds functionality for working with the loom
*/
var ARRAY_SLICE = Array.prototype.slice;
var $ELEMENT = "$element";
var SELECTOR_WEAVE = "[" + config.widget.weave + "]";
var SELECTOR_WOVEN = "[" + config.widget.woven + "]";
var FINALIZE = config.phase.finalize;
/**
* @method constructor
* @inheritdoc
*/
return Component.extend({
"displayName": "widget/component",
/**
* Handles component render
* @handler
* @inheritdoc #event-sig/render
* @localdoc Calls {@link #method-weave} to ensure newly rendered html is woven
*/
"sig/render": function ($target) {
return weave.apply($target.find(SELECTOR_WEAVE).addBack(SELECTOR_WEAVE), ARRAY_SLICE.call(arguments, 1));
},
/**
* @handler
* @inheritdoc #event-dom/destroy
* @localdoc Calls {@link #method-unweave} to ensure this element is unwoven
*/
"dom/destroy": function () {
if (this.phase !== FINALIZE) {
unweave.call(this[$ELEMENT]);
}
},
/**
* @method
* @inheritdoc widget.weave#constructor
*/
"weave": function () {
return weave.apply(this[$ELEMENT].find(SELECTOR_WEAVE), ARRAY_SLICE.call(arguments));
},
/**
* @inheritdoc widget.unweave#constructor
*/
"unweave": function () {
return unweave.apply(this[$ELEMENT].find(SELECTOR_WOVEN), arguments);
},
/**
* @inheritdoc widget.woven#constructor
*/
"woven": function () {
return woven.apply(this[$ELEMENT].find(SELECTOR_WOVEN), arguments);
}
});
});