forked from kaelzhang/neuron.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.js
More file actions
116 lines (88 loc) · 2.88 KB
/
step.js
File metadata and controls
116 lines (88 loc) · 2.88 KB
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
110
111
112
113
114
115
116
var
ITEM_RENDERER = 'itemRenderer',
METHODS_OVERRIDEN = {
/**
* override the _getItem method
* so it could generate unexisted items
* @param {number} index
* @param {boolean=} dontSetPos if true, _getItem method will not set the position of newly created item
*/
_getItem: function(index, dontSetPos){
var self = this,
item = self.items[index];
if(!item){
item = self.items[index] = self[ITEM_RENDERER].call(self, index);
}
return self._plantItem(item, index, dontSetPos);
}
};
module.exports = {
name: 'step',
ATTRS: {
// async: false,
/**
* method to render the Neuron/DOM instance of the item of expected index
* @returns {string} the Neuron/DOM instance of the item with <index> index
*/
itemRenderer: {
// type {function(index, callback)}
validator: NR.isFunction,
setter: function(v){
return this[ITEM_RENDERER] = v;
}
},
data: {
value: [],
validator: NR.isArray
},
dataLength: {
value: 0,
validator: NR.isNumber,
getter: function(v){
return v || this.get('data').length;
}
},
itemSpace: null
},
init: function(self){
var EVENTS = self.get('EVENTS');
self.on(EVENTS.BEFORE_SWITCH, function(){
var self = this,
move = self.get('stage'),
length = self.length,
now = self.expectIndex,
end = now + move,
index;
// check the existance of the items in the expected page which the switcher is switching to
while(now < end){
index = self._limit(now ++);
index >= self.originLength && self._getItem(index);
}
});
self.on(EVENTS.BEFORE_INIT, function(){
// override
NR.mix(this, METHODS_OVERRIDEN);
});
self.on(EVENTS.AFTER_INIT, function(){
var self = this,
length = self.originLength;
// set fake length value
self._itemData(length + self.get('dataLength'));
});
}
};
/**
2012-04-25 Kael:
- [issue.11-09].A
- fix a bug which is caused by confusing ATTR.move with ATTR.stage
2011-11-17 Kael:
TODO:
A. async itemRenderer(blocked by B)
B. queue with multiple threads support
2011-11-09 Kael:
issue:
A. if items don't exist, _getItem will fail
2011-11-02 Kael:
- complete plugin::step
- refractor _getItem method, so it could authentically create new items and apply them to precise positions
*/