Example #1
0
 MdInputContainer.prototype.ngAfterContentInit = function () {
     var _this = this;
     if (this._input === null) {
         return;
     }
     async_1.TimerWrapper.setTimeout(function () { return _this.ngOnChanges({}); }, 0);
     async_1.ObservableWrapper.subscribe(this._input.mdChange, function (value) {
         _this.inputHasValue = value !== '';
     });
     async_1.ObservableWrapper.subscribe(this._input.mdFocusChange, function (hasFocus) {
         _this.inputHasFocus = hasFocus;
     });
 };
 constructor(bus, _serializer, _zone) {
     this._serializer = _serializer;
     this._zone = _zone;
     this._eventDispatchRegistry = new Map();
     var source = bus.from(EVENT_CHANNEL);
     ObservableWrapper.subscribe(source, (message) => this._dispatchEvent(new RenderEventData(message, _serializer)));
 }
Example #3
0
 function WebWorkerPlatformLocation(brokerFactory, bus, _serializer) {
     var _this = this;
     _super.call(this);
     this._serializer = _serializer;
     this._popStateListeners = [];
     this._hashChangeListeners = [];
     this._location = null;
     this._broker = brokerFactory.createMessageBroker(messaging_api_1.ROUTER_CHANNEL);
     this._channelSource = bus.from(messaging_api_1.ROUTER_CHANNEL);
     async_1.ObservableWrapper.subscribe(this._channelSource, function (msg) {
         var listeners = null;
         if (collection_1.StringMapWrapper.contains(msg, 'event')) {
             var type = msg['event']['type'];
             if (lang_1.StringWrapper.equals(type, "popstate")) {
                 listeners = _this._popStateListeners;
             }
             else if (lang_1.StringWrapper.equals(type, "hashchange")) {
                 listeners = _this._hashChangeListeners;
             }
             if (listeners !== null) {
                 var e_1 = event_deserializer_1.deserializeGenericEvent(msg['event']);
                 // There was a popState or hashChange event, so the location object thas been updated
                 _this._location = _this._serializer.deserialize(msg['location'], serialized_types_1.LocationType);
                 listeners.forEach(function (fn) { return fn(e_1); });
             }
         }
     });
 }
 ObservablePipe.prototype._dispose = function () {
     async_1.ObservableWrapper.dispose(this._subscription);
     this._latestValue = null;
     this._latestReturnedValue = null;
     this._subscription = null;
     this._observable = null;
 };
 constructor(brokerFactory, bus, _serializer) {
     super();
     this._serializer = _serializer;
     this._popStateListeners = [];
     this._hashChangeListeners = [];
     this._location = null;
     this._broker = brokerFactory.createMessageBroker(ROUTER_CHANNEL);
     this._channelSource = bus.from(ROUTER_CHANNEL);
     ObservableWrapper.subscribe(this._channelSource, (msg) => {
         var listeners = null;
         if (StringMapWrapper.contains(msg, 'event')) {
             let type = msg['event']['type'];
             if (StringWrapper.equals(type, "popstate")) {
                 listeners = this._popStateListeners;
             }
             else if (StringWrapper.equals(type, "hashchange")) {
                 listeners = this._hashChangeListeners;
             }
             if (listeners !== null) {
                 let e = deserializeGenericEvent(msg['event']);
                 // There was a popState or hashChange event, so the location object thas been updated
                 this._location = this._serializer.deserialize(msg['location'], LocationType);
                 listeners.forEach((fn) => fn(e));
             }
         }
     });
 }
Example #6
0
 _ngZone.runOutsideAngular(function () {
     async_1.ObservableWrapper.subscribe(_ngZone.onEventDone, function (_) {
         if (!_ngZone.hasPendingTimers) {
             _this._isAngularEventPending = false;
             _this._runCallbacksIfReady();
         }
     });
 });
 function WebWorkerEventDispatcher(bus, _serializer) {
     var _this = this;
     this._serializer = _serializer;
     this._eventDispatchRegistry = new collection_1.Map();
     bus.initChannel(messaging_api_1.EVENT_CHANNEL);
     var source = bus.from(messaging_api_1.EVENT_CHANNEL);
     async_1.ObservableWrapper.subscribe(source, function (message) { return _this._dispatchEvent(new RenderEventData(message, _serializer)); });
 }
Example #8
0
 _runAsyncValidator(emitEvent) {
     if (isPresent(this.asyncValidator)) {
         this._status = PENDING;
         this._cancelExistingSubscription();
         var obs = toObservable(this.asyncValidator(this));
         this._asyncValidationSubscription = ObservableWrapper.subscribe(obs, (res) => this.setErrors(res, { emitEvent: emitEvent }));
     }
 }
Example #9
0
 updateValueAndValidity({ onlySelf, emitEvent } = {}) {
     onlySelf = normalizeBool(onlySelf);
     emitEvent = isPresent(emitEvent) ? emitEvent : true;
     this._updateValue();
     this._errors = this._runValidator();
     this._status = this._calculateStatus();
     if (this._status == VALID || this._status == PENDING) {
         this._runAsyncValidator(emitEvent);
     }
     if (emitEvent) {
         ObservableWrapper.callEmit(this._valueChanges, this._value);
         ObservableWrapper.callEmit(this._statusChanges, this._status);
     }
     if (isPresent(this._parent) && !onlySelf) {
         this._parent.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent });
     }
 }
 _unsubscribeFromOutputs() {
     if (isPresent(this.outputSubscriptions)) {
         for (var i = 0; i < this.outputSubscriptions.length; ++i) {
             ObservableWrapper.dispose(this.outputSubscriptions[i]);
             this.outputSubscriptions[i] = null;
         }
     }
 }
 this._ngZone.runOutsideAngular(() => {
     ObservableWrapper.subscribe(this._ngZone.onStable, (_) => {
         NgZone.assertNotInAngularZone();
         scheduleMicroTask(() => {
             this._isZoneStable = true;
             this._runCallbacksIfReady();
         });
     });
 });
Example #12
0
 AbstractControl.prototype.updateValueAndValidity = function (_a) {
     var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent;
     onlySelf = lang_1.normalizeBool(onlySelf);
     emitEvent = lang_1.isPresent(emitEvent) ? emitEvent : true;
     this._updateValue();
     this._errors = this._runValidator();
     this._status = this._calculateStatus();
     if (this._status == exports.VALID || this._status == exports.PENDING) {
         this._runAsyncValidator(emitEvent);
     }
     if (emitEvent) {
         async_1.ObservableWrapper.callNext(this._valueChanges, this._value);
         async_1.ObservableWrapper.callNext(this._statusChanges, this._status);
     }
     if (lang_1.isPresent(this._parent) && !onlySelf) {
         this._parent.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent });
     }
 };
 constructor(messageBus, _serializer, channel) {
     super();
     this.channel = channel;
     this._pending = new Map();
     this._sink = messageBus.to(channel);
     this._serializer = _serializer;
     var source = messageBus.from(channel);
     ObservableWrapper.subscribe(source, (message) => this._handleMessage(message));
 }
 function ClientMessageBroker_(messageBus, _serializer, channel) {
     var _this = this;
     _super.call(this);
     this.channel = channel;
     this._pending = new Map();
     this._sink = messageBus.to(channel);
     this._serializer = _serializer;
     var source = messageBus.from(channel);
     async_1.ObservableWrapper.subscribe(source, function (message) { return _this._handleMessage(message); });
 }
Example #15
0
 AbstractControl.prototype._runAsyncValidator = function (emitEvent) {
     var _this = this;
     if (lang_1.isPresent(this.asyncValidator)) {
         this._status = exports.PENDING;
         this._cancelExistingSubscription();
         var obs = toObservable(this.asyncValidator(this));
         this._asyncValidationSubscription =
             async_1.ObservableWrapper.subscribe(obs, function (res) { return _this.setErrors(res, { emitEvent: emitEvent }); });
     }
 };
 function ServiceMessageBroker_(messageBus, _serializer, channel) {
     var _this = this;
     _super.call(this);
     this._serializer = _serializer;
     this.channel = channel;
     this._methods = new collection_1.Map();
     this._sink = messageBus.to(channel);
     var source = messageBus.from(channel);
     async_1.ObservableWrapper.subscribe(source, function (message) { return _this._handleMessage(message); });
 }
Example #17
0
 AsyncPipe.prototype._selectStrategy = function (obj) {
     if (lang_1.isPromise(obj)) {
         return _promiseStrategy;
     }
     else if (async_1.ObservableWrapper.isObservable(obj)) {
         return _observableStrategy;
     }
     else {
         throw new invalid_pipe_argument_exception_1.InvalidPipeArgumentException(AsyncPipe, obj);
     }
 };
Example #18
0
 /**
  * Sets errors on a control.
  *
  * This is used when validations are run not automatically, but manually by the user.
  *
  * Calling `setErrors` will also update the validity of the parent control.
  *
  * ## Usage
  *
  * ```
  * var login = new Control("someLogin");
  * login.setErrors({
  *   "notUnique": true
  * });
  *
  * expect(login.valid).toEqual(false);
  * expect(login.errors).toEqual({"notUnique": true});
  *
  * login.updateValue("someOtherLogin");
  *
  * expect(login.valid).toEqual(true);
  * ```
  */
 setErrors(errors, { emitEvent } = {}) {
     emitEvent = isPresent(emitEvent) ? emitEvent : true;
     this._errors = errors;
     this._status = this._calculateStatus();
     if (emitEvent) {
         ObservableWrapper.callEmit(this._statusChanges, this._status);
     }
     if (isPresent(this._parent)) {
         this._parent._updateControlsErrors();
     }
 }
Example #19
0
 /** @internal */
 _selectStrategy(obj) {
     if (isPromise(obj)) {
         return _promiseStrategy;
     }
     else if (ObservableWrapper.isObservable(obj)) {
         return _observableStrategy;
     }
     else {
         throw new InvalidPipeArgumentException(AsyncPipe, obj);
     }
 }
Example #20
0
 AbstractControl.prototype.setErrors = function (errors, _a) {
     var emitEvent = (_a === void 0 ? {} : _a).emitEvent;
     emitEvent = lang_1.isPresent(emitEvent) ? emitEvent : true;
     this._errors = errors;
     this._status = this._calculateStatus();
     if (emitEvent) {
         async_1.ObservableWrapper.callNext(this._statusChanges, this._status);
     }
     if (lang_1.isPresent(this._parent)) {
         this._parent._updateControlsErrors();
     }
 };
Example #21
0
 AbstractControl.prototype.updateValueAndValidity = function (_a) {
     var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent;
     onlySelf = lang_1.isPresent(onlySelf) ? onlySelf : false;
     emitEvent = lang_1.isPresent(emitEvent) ? emitEvent : true;
     this._updateValue();
     if (emitEvent) {
         async_1.ObservableWrapper.callNext(this._valueChanges, this._value);
     }
     this._errors = this.validator(this);
     this._status = lang_1.isPresent(this._errors) ? exports.INVALID : exports.VALID;
     if (lang_1.isPresent(this._parent) && !onlySelf) {
         this._parent.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent });
     }
 };
Example #22
0
 Testability.prototype._watchAngularEvents = function (_ngZone) {
     var _this = this;
     async_1.ObservableWrapper.subscribe(_ngZone.onTurnStart, function (_) {
         _this._didWork = true;
         _this._isAngularEventPending = true;
     });
     _ngZone.runOutsideAngular(function () {
         async_1.ObservableWrapper.subscribe(_ngZone.onEventDone, function (_) {
             if (!_ngZone.hasPendingTimers) {
                 _this._isAngularEventPending = false;
                 _this._runCallbacksIfReady();
             }
         });
     });
 };
 ClientMessageBroker_.prototype.runOnService = function (args, returnType) {
     var _this = this;
     var fnArgs = [];
     if (lang_1.isPresent(args.args)) {
         args.args.forEach(function (argument) {
             if (argument.type != null) {
                 fnArgs.push(_this._serializer.serialize(argument.value, argument.type));
             }
             else {
                 fnArgs.push(argument.value);
             }
         });
     }
     var promise;
     var id = null;
     if (returnType != null) {
         var completer = async_1.PromiseWrapper.completer();
         id = this._generateMessageId(args.method);
         this._pending.set(id, completer);
         async_1.PromiseWrapper.catchError(completer.promise, function (err, stack) {
             lang_1.print(err);
             completer.reject(err, stack);
         });
         promise = async_1.PromiseWrapper.then(completer.promise, function (value) {
             if (_this._serializer == null) {
                 return value;
             }
             else {
                 return _this._serializer.deserialize(value, returnType);
             }
         });
     }
     else {
         promise = null;
     }
     // TODO(jteplitz602): Create a class for these messages so we don't keep using StringMap #3685
     var message = { 'method': args.method, 'args': fnArgs };
     if (id != null) {
         message['id'] = id;
     }
     async_1.ObservableWrapper.callEmit(this._sink, message);
     return promise;
 };
Example #24
0
 _destroyLocal() {
     var hostElement = this.type === ViewType.COMPONENT ? this.declarationAppElement.nativeElement : null;
     for (var i = 0; i < this.disposables.length; i++) {
         this.disposables[i]();
     }
     for (var i = 0; i < this.subscriptions.length; i++) {
         ObservableWrapper.dispose(this.subscriptions[i]);
     }
     this.destroyInternal();
     if (this._hasExternalHostElement) {
         this.renderer.detachView(this.flatRootNodes);
     }
     else if (isPresent(this.viewContainerElement)) {
         this.viewContainerElement.detachView(this.viewContainerElement.nestedViews.indexOf(this));
     }
     else {
         this.dirtyParentQueriesInternal();
     }
     this.renderer.destroyView(hostElement, this.allNodes);
 }
Example #25
0
 onSubmit() {
     ObservableWrapper.callEmit(this.ngSubmit, null);
     return false;
 }
Example #26
0
 MessageBasedPlatformLocation.prototype._sendUrlChangeEvent = function (e) {
     var loc = this._serializer.serialize(this._platformLocation.location, serialized_types_1.LocationType);
     var serializedEvent = { 'type': e.type };
     async_1.ObservableWrapper.callEmit(this._channelSink, { 'event': serializedEvent, 'location': loc });
 };
Example #27
0
 subscribe(onNext, onThrow = null, onReturn = null) {
     return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
 }
Example #28
0
 simulateHashChange(pathname) {
     // Because we don't prevent the native event, the browser will independently update the path
     this.setInitialPath(pathname);
     this.urlChanges.push('hash: ' + pathname);
     ObservableWrapper.callEmit(this._subject, { 'url': pathname, 'pop': true, 'type': 'hashchange' });
 }
Example #29
0
 simulateUrlPop(pathname) {
     ObservableWrapper.callEmit(this._subject, { 'url': pathname, 'pop': true });
 }
Example #30
0
function _convertToPromise(obj) {
    return promise_1.PromiseWrapper.isPromise(obj) ? obj : async_1.ObservableWrapper.toPromise(obj);
}