How does angular2 detect changes in the state pipe?

I created a simple state link based on the Angular.io protocol tutorial :

@Pipe({
    name: 'fetch',
    pure: false
})

class FetchJsonPipe  implements PipeTransform{
    private fetchedValue = 'waiting';
    private fetchedValue2 = 'waiting2';

    transform(value:string, args:string[]):any {
        setTimeout(() => {
            this.fetchedValue = 'done';
            this.fetchedValue2 = 'done2';
        }, 3000);
        return this.fetchedValue2;
    }
}

@Component({ selector: 'sd-splash'
           , template: 'hello ng2 {{ "5" | fetch }}'
           , pipes: [FetchJsonPipe]
           })

My question is: I am returning this.fetchedValuefrom #transformimmediately. Since this is just a string, it returns by value. Later, when the timeout I just assign a value to the 'done'property (which is also private).

How does Angular2 know that the final result is 'waiting'not final? How does he know that the updated value will be available through #fetchedValue? The promise is not disclosed at all, and Angular2 does not have information about the name from the field; I save the result.

, , - pure == false, , , . , .

! , .

+4
2

Angular monkey ( setTimeout()) Zone.js. , AngularJS .

, AngularJS , .

AngularJS , (.. args).

+6

, , Zone.js. angular zone $rootScope setTimeout ( )

, , .

, , , .

+2

Source: https://habr.com/ru/post/1623692/


All Articles