@@ -83,11 +83,8 @@ function Compiler (vm, options) {
83
83
// setup observer
84
84
compiler . setupObserver ( )
85
85
86
- // pre compile / created hook
87
- var created = options . beforeCompile || options . created
88
- if ( created ) {
89
- created . call ( vm , options )
90
- }
86
+ // beforeCompile hook
87
+ compiler . execHook ( 'beforeCompile' , 'created' )
91
88
92
89
// create bindings for things already in scope
93
90
var key , keyPrefix
@@ -125,10 +122,7 @@ function Compiler (vm, options) {
125
122
compiler . init = false
126
123
127
124
// post compile / ready hook
128
- var ready = options . afterCompile || options . ready
129
- if ( ready ) {
130
- ready . call ( vm , options )
131
- }
125
+ compiler . execHook ( 'afterCompile' , 'ready' )
132
126
}
133
127
134
128
var CompilerProto = Compiler . prototype
@@ -549,6 +543,17 @@ CompilerProto.getOption = function (type, id) {
549
543
return ( opts [ type ] && opts [ type ] [ id ] ) || ( utils [ type ] && utils [ type ] [ id ] )
550
544
}
551
545
546
+ /**
547
+ * Execute a user hook
548
+ */
549
+ CompilerProto . execHook = function ( id , alt ) {
550
+ var opts = this . options ,
551
+ hook = opts [ id ] || opts [ alt ]
552
+ if ( hook ) {
553
+ hook . call ( this . vm , opts )
554
+ }
555
+ }
556
+
552
557
/**
553
558
* Unbind and remove element
554
559
*/
@@ -560,14 +565,9 @@ CompilerProto.destroy = function () {
560
565
el = compiler . el ,
561
566
directives = compiler . dirs ,
562
567
exps = compiler . exps ,
563
- bindings = compiler . bindings ,
564
- beforeDestroy = compiler . options . beforeDestroy ,
565
- afterDestroy = compiler . options . afterDestroy
568
+ bindings = compiler . bindings
566
569
567
- // call user teardown first
568
- if ( beforeDestroy ) {
569
- beforeDestroy . call ( vm )
570
- }
570
+ compiler . execHook ( 'beforeDestroy' )
571
571
572
572
// unwatch
573
573
compiler . observer . off ( )
@@ -621,10 +621,7 @@ CompilerProto.destroy = function () {
621
621
vm . $remove ( )
622
622
}
623
623
624
- // post teardown hook
625
- if ( afterDestroy ) {
626
- afterDestroy . call ( vm )
627
- }
624
+ compiler . execHook ( 'afterDestroy' )
628
625
}
629
626
630
627
// Helpers --------------------------------------------------------------------
0 commit comments