Декораторы выполняются дважды в угловых 2 env
Играя с декораторами, в среде ng2 (на основе ang-cli) я написал файл.spec.ts. Я ожидал этого:
- Оценка выражения будет сверху вниз
- Результаты будут функциями и будут выполняться снизу вверх.
И то, и другое происходит (как и ожидалось), и это нормально, но все выполняется дважды.
Смотрите ниже: =
testchild1.spec.ts
//fdescribe("Ang2: just execute this suite only", function(){
//(function) expression evaluation is top-down
//results (of functions) are then called as functions from down-top
function f(){
console.log('f() expression evaluated ');
return function(tar, x:string, descriptor: PropertyDescriptor){
console.log('f() called');
}
}
function g(){
console.log('g() expression evaluated ');
return function(tar, x:string, descriptor: PropertyDescriptor){
console.log('g() called');
}
}
class C{
@f()
@g()
somemethod(){
console.log('inside somemethod');
}
} //class C ends.
//});
O / P:-
D:\js\Ang2\proj2\ngrxproj03>ng test src/app/testchild1/testchild1.spec.ts
Your global Angular CLI version (1.1.2) is greater than your local
version (1.1.1). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
10% building modules 1/1 modules 0 active19 06 2017 15:30:16.929:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
19 06 2017 15:30:16.932:INFO [launcher]: Launching browser Chrome with unlimited concurrency
19 06 2017 15:30:16.940:INFO [launcher]: Starting browser Chrome
19 06 2017 15:30:30.788:INFO [Chrome 58.0.3029 (Windows 8 0.0.0)]: Connected on socket qmmNpsc8yjStv6b-AAAA with id 45423503
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'f() expression evaluated '
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'f() expression evaluated '
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'g() expression evaluated '
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'g() expression evaluated '
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'g() called'
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'g() called'
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'f() called'
Chrome 58.0.3029 (Windows 8 0.0.0) LOG: 'f() called'
Chrome 58.0.3029 (Windows 8 0.0.0): Executed 2 of 6 (skipped 4) SUCCESS (0.092 secs / 0.187 secs)
Посмотрите, как все вызывается дважды. Я делаю что-то (это очевидно) неправильно?
Любые указатели были бы великолепны. (Потратили впустую полдня на это)