/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Observable } from 'rxjs'; /** Mixin to augment a directive with an initialized property that will emits when ngOnInit ends. */ export function mixinInitialized(base) { return class extends base { constructor(...args) { super(...args); /** Whether this directive has been marked as initialized. */ this._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. */ this._pendingSubscribers = []; /** * Observable stream that emits when the directive initializes. If already initialized, the * subscriber is stored to be notified once _markInitialized is called. */ this.initialized = new Observable(subscriber => { // If initialized, immediately notify the subscriber. Otherwise store the subscriber to notify // when _markInitialized is called. if (this._isInitialized) { this._notifySubscriber(subscriber); } else { this._pendingSubscribers.push(subscriber); } }); } /** * Marks the state as initialized and notifies pending subscribers. Should be called at the end * of ngOnInit. * @docs-private */ _markInitialized() { if (this._isInitialized && (typeof ngDevMode === 'undefined' || ngDevMode)) { 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(); } }; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5pdGlhbGl6ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvY29yZS9jb21tb24tYmVoYXZpb3JzL2luaXRpYWxpemVkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxVQUFVLEVBQWEsTUFBTSxNQUFNLENBQUM7QUF3QjVDLG9HQUFvRztBQUNwRyxNQUFNLFVBQVUsZ0JBQWdCLENBQTRCLElBQU87SUFDakUsT0FBTyxLQ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