@@ -7,14 +7,20 @@ var Emitter = require('./emitter'),
7
7
TextParser = require ( './text-parser' ) ,
8
8
DepsParser = require ( './deps-parser' ) ,
9
9
ExpParser = require ( './exp-parser' ) ,
10
+
11
+ // cache methods
10
12
slice = Array . prototype . slice ,
11
13
log = utils . log ,
12
14
def = utils . defProtected ,
15
+
16
+ // special directives
17
+ idAttr ,
13
18
vmAttr ,
19
+ preAttr ,
14
20
repeatAttr ,
15
21
partialAttr ,
16
- transitionAttr ,
17
- preAttr
22
+ transitionAttr
23
+
18
24
19
25
/**
20
26
* The DOM compiler
@@ -40,8 +46,9 @@ function Compiler (vm, options) {
40
46
41
47
compiler . vm = vm
42
48
// special VM properties are inumerable
43
- def ( vm , '$compiler ' , compiler )
49
+ def ( vm , '$' , { } )
44
50
def ( vm , '$el' , compiler . el )
51
+ def ( vm , '$compiler' , compiler )
45
52
46
53
// keep track of directives and expressions
47
54
// so they can be unbound during destroy()
@@ -65,6 +72,12 @@ function Compiler (vm, options) {
65
72
? getRoot ( parent )
66
73
: compiler
67
74
75
+ // register child id on parent
76
+ var childId = compiler . el . getAttribute ( idAttr )
77
+ if ( childId && parent ) {
78
+ parent . vm . $ [ childId ] = vm
79
+ }
80
+
68
81
// setup observer
69
82
compiler . setupObserver ( )
70
83
@@ -182,12 +195,14 @@ CompilerProto.compile = function (node, root) {
182
195
if ( node . nodeType === 1 ) {
183
196
// a normal node
184
197
if ( node . hasAttribute ( preAttr ) ) return
185
- var repeatExp = node . getAttribute ( repeatAttr ) ,
186
- vmId = node . getAttribute ( vmAttr ) ,
198
+ var vmId = node . getAttribute ( vmAttr ) ,
199
+ repeatExp = node . getAttribute ( repeatAttr ) ,
187
200
partialId = node . getAttribute ( partialAttr )
188
201
// we need to check for any possbile special directives
189
202
// e.g. sd-repeat, sd-viewmodel & sd-partial
190
203
if ( repeatExp ) { // repeat block
204
+ // repeat block cannot have sd-id at the same time.
205
+ node . removeAttribute ( idAttr )
191
206
var directive = Directive . parse ( repeatAttr , repeatExp , compiler , node )
192
207
if ( directive ) {
193
208
compiler . bindDirective ( directive )
@@ -592,11 +607,12 @@ CompilerProto.destroy = function () {
592
607
*/
593
608
function refreshPrefix ( ) {
594
609
var prefix = config . prefix
595
- repeatAttr = prefix + '-repeat '
610
+ idAttr = prefix + '-id '
596
611
vmAttr = prefix + '-viewmodel'
612
+ preAttr = prefix + '-pre'
613
+ repeatAttr = prefix + '-repeat'
597
614
partialAttr = prefix + '-partial'
598
615
transitionAttr = prefix + '-transition'
599
- preAttr = prefix + '-pre'
600
616
}
601
617
602
618
/**
0 commit comments