it('should be in sync when unchanged document gets changed by other instance', async () => {
                const name = util.randomCouchString(10);
                const c1 = await humansCollection.createMultiInstance(name, 1);
                const c2 = await humansCollection.createMultiInstance(name, 0);
                const doc = await c1.findOne().exec();
                const doc2 = await c2.findOne().exec();
                assert.deepEqual(doc.firstName, doc2.firstName);
                assert.notEqual(doc, doc2);

                const ok = await doc.synced$.pipe(first()).toPromise();
                assert.ok(ok);

                doc2.firstName = 'foobar';
                await doc2.save();

                await AsyncTestUtil.waitUntil(async () => {
                    await c1.database.socket.pull();
                    await c2.database.socket.pull();
                    return doc.firstName === 'foobar';
                });
                assert.equal(doc.firstName, 'foobar');

                const ok2 = await doc.synced$.pipe(first()).toPromise();
                assert.ok(ok2);

                c1.database.destroy();
                c2.database.destroy();
            });
Exemple #2
0
        it('should emit deleted', async () => {
            const name = util.randomCouchString(10);
            const db = await RxDatabase.create({
                name,
                adapter: 'memory'
            });
            const db2 = await RxDatabase.create({
                name,
                adapter: 'memory',
                ignoreDuplicate: true
            });

            const doc1 = await db.insertLocal('foobar', {
                foo: 'bar'
            });
            const doc2 = await db2.getLocal('foobar');
            assert.ok(doc2);

            doc1.remove();

            await doc2.deleted$
            .pipe(
                filter(d => d === true),
                first()
            )
            .toPromise();

            db.destroy();
            db2.destroy();
        });
Exemple #3
0
 MatSnackBarContainer.prototype._completeExit = /**
  * Waits for the zone to settle before removing the element. Helps prevent
  * errors where we end up removing an element which is in the middle of an animation.
  * @return {?}
  */
 function () {
     var _this = this;
     this._ngZone.onMicrotaskEmpty.asObservable().pipe(first()).subscribe(function () {
         _this._onExit.next();
         _this._onExit.complete();
     });
 };
 it('should fire on save', async () => {
     const c = await humansCollection.create();
     const doc = await c.findOne().exec();
     doc.set('firstName', util.randomCouchString(8));
     doc.save();
     const changeEvent = await doc.$.pipe(first()).toPromise();
     assert.equal(changeEvent._id, doc.primary);
     c.database.destroy();
 });
Exemple #5
0
 MatFormField.prototype._animateAndLockPlaceholder = /**
  * Animates the placeholder up and locks it in position.
  * @return {?}
  */
 function () {
     var _this = this;
     if (this._placeholder && this._canPlaceholderFloat) {
         this._showAlwaysAnimate = true;
         this._floatPlaceholder = 'always';
         fromEvent(this._placeholder.nativeElement, 'transitionend').pipe(first()).subscribe(function () {
             _this._showAlwaysAnimate = false;
         });
         this._changeDetectorRef.markForCheck();
     }
 };
Exemple #6
0
 MatAutocompleteTrigger.prototype._subscribeToClosingActions = /**
  * This method listens to a stream of panel closing actions and resets the
  * stream every time the option list changes.
  * @return {?}
  */
 function () {
     var _this = this;
     var /** @type {?} */ firstStable = this._zone.onStable.asObservable().pipe(first());
     var /** @type {?} */ optionChanges = this.autocomplete.options.changes.pipe(tap(function () { return _this._positionStrategy.recalculateLastPosition(); }), 
     // Defer emitting to the stream until the next tick, because changing
     // bindings in here will cause "changed after checked" errors.
     delay(0));
     // When the zone is stable initially, and when the option list changes...
     return merge(firstStable, optionChanges)
         .pipe(
     // create a new stream of panelClosingActions, replacing any previous streams
     // that were created, and flatten it so our stream only emits closing events...
     switchMap(function () {
         _this._resetActiveItem();
         _this.autocomplete._setVisibility();
         return _this.panelClosingActions;
     }), 
     // when the first closing event occurs...
     first())
         .subscribe(function (event) { return _this._setValueAndClose(event); });
 };
Exemple #7
0
 MatTooltip.prototype._updateTooltipMessage = /**
  * Updates the tooltip message and repositions the overlay according to the new message length
  * @return {?}
  */
 function () {
     var _this = this;
     // Must wait for the message to be painted to the tooltip so that the overlay can properly
     // calculate the correct positioning based on the size of the text.
     if (this._tooltipInstance) {
         this._tooltipInstance.message = this.message;
         this._tooltipInstance._markForCheck();
         this._ngZone.onMicrotaskEmpty.asObservable().pipe(first()).subscribe(function () {
             if (_this._tooltipInstance) {
                 /** @type {?} */ ((_this._overlayRef)).updatePosition();
             }
         });
     }
 };
Exemple #8
0
 MatIcon.prototype.ngOnChanges = /**
  * @param {?} changes
  * @return {?}
  */
 function (changes) {
     var _this = this;
     // Only update the inline SVG icon if the inputs changed, to avoid unnecessary DOM operations.
     if (changes["svgIcon"]) {
         if (this.svgIcon) {
             var _a = this._splitIconName(this.svgIcon), namespace = _a[0], iconName = _a[1];
             this._iconRegistry.getNamedSvgIcon(iconName, namespace).pipe(first()).subscribe(function (svg) { return _this._setSvgElement(svg); }, function (err) { return console.log("Error retrieving icon: " + err.message); });
         }
         else {
             this._clearSvgElement();
         }
     }
     if (this._usingFontIcon()) {
         this._updateFontIconClasses();
     }
 };
 it('emit when collection is created', async () => {
     const db = await RxDatabase.create({
         name: util.randomCouchString(10),
         adapter: 'memory'
     });
     db.collection({
         name: 'myname',
         schema: schemas.human
     });
     const changeEvent = await db.$
         .pipe(
             filter(cEvent => cEvent.data.op === 'RxDatabase.collection'),
             first()
         ).toPromise();
     assert.equal(changeEvent.constructor.name, 'RxChangeEvent');
     assert.equal(changeEvent.data.v, 'myname');
     db.destroy();
 });
Exemple #10
0
 await AsyncTestUtil.waitUntil(async () => {
     await c1.database.socket.pull();
     await c2.database.socket.pull();
     const ok = await doc.synced$.pipe(first()).toPromise();
     return ok;
 });
Exemple #11
0
 await AsyncTestUtil.waitUntil(async () => {
     const notOk = await doc.synced$.pipe(first()).toPromise();
     return !notOk;
 });
Exemple #12
0
            return _regeneratorRuntime.wrap(function _callee11$(_context11) {
                while (1) {
                    switch (_context11.prev = _context11.next) {
                        case 0:
                            if (!this.isLeader) {
                                _context11.next = 2;
                                break;
                            }

                            return _context11.abrupt('return', Promise.resolve(true));

                        case 2:
                            if (this.isWaiting) {
                                _context11.next = 14;
                                break;
                            }

                            this.isWaiting = true;

                            // apply now
                            this.applyOnce();

                            fallbackIntervalTime = SIGNAL_TIME * 5;
                            _context11.t0 = this.electionChannel;
                            _context11.next = _context11.t0 === 'broadcast' ? 9 : _context11.t0 === 'socket' ? 11 : 13;
                            break;

                        case 9:
                            // apply when leader dies
                            this.subs.push(this.bc.$.pipe(filter(function (msg) {
                                return msg.type === 'death';
                            })).subscribe(function () {
                                return _this3.applyOnce();
                            }));
                            return _context11.abrupt('break', 13);

                        case 11:
                            // no message via socket, so just use the interval but set it lower
                            fallbackIntervalTime = SIGNAL_TIME * 2;
                            return _context11.abrupt('break', 13);

                        case 13:

                            // apply on interval incase leader dies without notification
                            _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
                                return _regeneratorRuntime.wrap(function _callee10$(_context10) {
                                    while (1) {
                                        switch (_context10.prev = _context10.next) {
                                            case 0:
                                                if (!(!_this3.destroyed && !_this3.isLeader)) {
                                                    _context10.next = 16;
                                                    break;
                                                }

                                                _context10.next = 3;
                                                return util.promiseWait(fallbackIntervalTime);

                                            case 3:
                                                _context10.t0 = _this3.electionChannel;
                                                _context10.next = _context10.t0 === 'broadcast' ? 6 : _context10.t0 === 'socket' ? 9 : 12;
                                                break;

                                            case 6:
                                                _context10.next = 8;
                                                return util.requestIdlePromise(fallbackIntervalTime);

                                            case 8:
                                                return _context10.abrupt('break', 12);

                                            case 9:
                                                _context10.next = 11;
                                                return _this3.database.requestIdlePromise(fallbackIntervalTime);

                                            case 11:
                                                return _context10.abrupt('break', 12);

                                            case 12:
                                                _context10.next = 14;
                                                return _this3.applyOnce();

                                            case 14:
                                                _context10.next = 0;
                                                break;

                                            case 16:
                                            case 'end':
                                                return _context10.stop();
                                        }
                                    }
                                }, _callee10, _this3);
                            }))();

                        case 14:
                            return _context11.abrupt('return', this.becomeLeader$.asObservable().pipe(filter(function (i) {
                                return i.isLeader === true;
                            }), first()).toPromise());

                        case 15:
                        case 'end':
                            return _context11.stop();
                    }
                }
            }, _callee11, this);
Exemple #13
0
 MatSnackBar.prototype._attach = /**
  * Places a new component as the content of the snack bar container.
  * @template T
  * @param {?} component
  * @param {?} config
  * @return {?}
  */
 function (component, config) {
     var /** @type {?} */ overlayRef = this._createOverlay(config);
     var /** @type {?} */ container = this._attachSnackBarContainer(overlayRef, config);
     var /** @type {?} */ snackBarRef = new MatSnackBarRef(container, overlayRef);
     var /** @type {?} */ injector = this._createInjector(config, snackBarRef);
     var /** @type {?} */ portal = new ComponentPortal(component, undefined, injector);
     var /** @type {?} */ contentRef = container.attachComponentPortal(portal);
     // We can't pass this via the injector, because the injector is created earlier.
     snackBarRef.instance = contentRef.instance;
     // Subscribe to the breakpoint observer and attach the mat-snack-bar-handset class as
     // appropriate. This class is applied to the overlay element because the overlay must expand to
     // fill the width of the screen for full width snackbars.
     this._breakpointObserver.observe(Breakpoints.Handset).pipe(takeUntil(overlayRef.detachments().pipe(first()))).subscribe(function (state$$1) {
         if (state$$1.matches) {
             overlayRef.overlayElement.classList.add('mat-snack-bar-handset');
         }
         else {
             overlayRef.overlayElement.classList.remove('mat-snack-bar-handset');
         }
     });
     return snackBarRef;
 };