license import { Observable , Subscriber } from 'rxjs' ; import { Constructor } from './constructor' ; docs-private export interface HasInitialized { /** Stream that emits once during the directive/component's ngOnInit. */ initialized : Observable < void > ; docs-private _markInitialized : ( ) => void ; } docs-private export type HasInitializedCtor = Constructor < HasInitialized > ; /** Mixin to augment a directive with an initialized property that will emits when ngOnInit ends. */ export function mixinInitialized < T extends Constructor < { } > > ( base ) { return class extends base { /** Whether this directive has been marked as initialized. */ _isInitialized = false ; /**
         * List of subscribers that subscribed before the directive was initialized. Should be notified
         * during _markInitialized. Set to null after pending subscribers are notified, and should
         * not expect to be populated after.
         */ _pendingSubscribers : Subscriber < void > [ ] | null = [ ] ; /**
         * Observable stream that emits when the directive initializes. If already initialized, the
         * subscriber is stored to be notified once _markInitialized is called.
         */ initialized = new Observable < void > ( subscriber => { if ( this . _isInitialized ) { this . _notifySubscriber ( subscriber ) ; } else { this . _pendingSubscribers ! . push ( subscriber ) ; } } ) ; constructor ( ... args ) { super ( ... args ) ; } docs-private _markInitialized ( ) { if ( this . _isInitialized ) { throw Error ( 'This directive has already been marked as initialized and ' + 'should not be called twice.' ) ; } this . _isInitialized = true ; this . _pendingSubscribers ! . forEach ( this . _notifySubscriber ) ; this . _pendingSubscribers = null ; } /** Emits and completes the subscriber stream (should only emit once). */ _notifySubscriber ( subscriber ) { subscriber . next ( ) ; subscriber . complete ( ) ; } } ; }