constructor(public store: Store<any[]>) {
   this.filteredTodos = Observable.combineLatest(store.select('todos'), store.select('visibility'), (todos: any, visibilityFilter: any) => todos.filter(visibilityFilter.filter));
   this.todos = store.select('todos');
   this.visibilityFilter = store.select('visibility');
   this.completedCount = this.todos.map((todos: any) => todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0));
   this.activeCount = this.todos.map((todos: any) => todos.length - (todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0)));
 }
    ngOnInit() {
        this.codeList = this.tagList.tags$
            .map(tags => tags.map(tag => tag.id))
            .switchMap(tagIds => this.codeService.getAllCodes(tagIds));

        this.showList = this.codeList.map(codes => codes.length > 0);
        this.showEmptyMessage = this.showList.map(showList => !showList);
    }
Example #3
0
 protected handleResponse(entity: Observable<Response>): Observable<T> {
     return entity.map(this.extractData)
        .catch((err: any, caught: Observable<T>) => {
            if (this.config.handleError) this.config.handleError(err, caught);
            return Observable.throw(err);
        });
 }
Example #4
0
  request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
    const tokenPromise: Promise<string> = this._keycloakService.getToken();
    const tokenObservable: Observable<string> = Observable.fromPromise(tokenPromise);

    if (typeof url === 'string') {
      return tokenObservable.map(token => {
        const authOptions = new RequestOptions({headers: new Headers({'Authorization': 'Bearer ' + token})});
        return new RequestOptions().merge(options).merge(authOptions);
      }).concatMap(opts => super.request(url, opts));
    } else if (url instanceof Request) {
      return tokenObservable.map(token => {
        url.headers.set('Authorization', 'Bearer ' + token);
        return url;
      }).concatMap(request => super.request(request));
    }
  }
Example #5
0
 private createRequest(type: string,data ?: Object) : Observable<any> {
   let _url : string = this.buildUrl(data);
   let _request : Observable<any>
   let stringParam : string = '';
   let _jsonBuild : any = {}
   if(_url.split('?')[1] && _url.split('?')[1].length) {
     (_url.split('?')[1].split('&')).forEach( _paramPart => {
       _jsonBuild[_paramPart.split('=')[0]] = _paramPart.split('=')[1];
     });
     stringParam = JSON.stringify(_jsonBuild);
   }
   switch (type) {
     case "post":
       _request = this._http.post(_url.split('?')[0], stringParam);
       break;
     case "patch":
       _request = this._http.patch(_url.split('?')[0], stringParam);
       break;
     case "put":
       _request = this._http.put(_url.split('?')[0], stringParam);
       break;
     case "delete":
       _request = this._http.delete(_url);
       break;
     case "head":
       _request = this._http.head(_url);
       break;
     default:
       _request = this._http.get(_url);
       break;
   }
   this._request = _request.map((response: Response) => response.json());
   return this._request;
 }
Example #6
0
export function invokeCommand<TObj extends ReactiveObject, TArg, TResult>(source: Observable<TArg>, obj: TObj, command: string | ReactiveCommand<TArg, TResult>): Observable<TResult> {
    var commandObservable: Observable<ReactiveCommand<TArg, TResult>>;
    var canExecute: Observable<boolean>;
    var isExecuting: Observable<boolean>;
    if (typeof command === "string") {
        // Make sure that the current command is observed
        commandObservable = obj.whenSingle(command, true).map(e => e.newPropertyValue);
        canExecute = commandObservable.map(c => c.canExecute).switch();
    } else {
        commandObservable = Observable.of(command);
        canExecute = command.canExecute;
    }
    var results = source
        .withLatestFrom(commandObservable, canExecute, (v1, command, canExecute) => {
            return {
                canExecute,
                command,
                observedValue: v1
            };
        })
        .filter(o => o.canExecute && o.command != null)
        .distinctUntilChanged()
        .flatMap(o => {
            return o.command.execute(o.observedValue);
        });
    return results;
}
 ngOnInit() {
    
     const peopleSignal: Observable<{}> = Observable.create(observer => {
         this.addNewPerson = () => observer.next();
     }).share();
     
     const startForm = [];
     for (let i = 0; i < 10000; i++){
         startForm[i] = new Form();
     }
     
     this.forms =  peopleSignal.map(() => [new Form()])
     .startWith(startForm)
     .scan((acc: Form[], value) => acc.concat(value));
      
     this.numberOfPeople = this.forms.map(forms => forms.length);
      
 }
Example #8
0
 // TODO There has to be a better way.
 /**
  *
  * @returns {Observable<R>}
  */
 public getUserLists(): Observable<Observable<FirebaseObjectObservable<any>[]>> {
   let userIdObservable: Observable<string> = this.authenticationService.observableUserId;
   return userIdObservable.map((uuid) => {
     return this.angularFire.database.list('users/' + uuid + '/task_lists').map((taskLists) => {
       return taskLists.map((taskList) => {
         return this.angularFire.database.object(TASK_LIST_METADATA_PATH + '/' + taskList['$key']);
       });
     });
   });
 }
 constructor(fb: FormBuilder) {
    
     const peopleSignal: Observable<{}> = Observable.create(observer => {
         this.addNewPerson = () => observer.next();
     });
     
     this.people =  peopleSignal.map(() => [new Person()])
     .startWith([new Person()])
     .scan((acc: Person[], value) => acc.concat(value));
      
 }
Example #10
0
    constructor(
        private _http: Http,
        private _notes: NotificationsService,
        private _trackService: TrackService,
        private _configService: ConfigService
    ) {
        // Api base
        this._apiBase = _configService._baseApi + 'projects/';

        // Local datastore
        this._dataStore = {
            credits: [],
            trackCredits: [],
            selectedTrack: undefined
        };

        // Credits stream
        this.credits$ = new Observable(observer => this._creditsObserver = observer).share();

        // Update track credits when a new track is selected
        this._trackService.selectedTrack$.subscribe(selectedTrack => {
            this._dataStore.selectedTrack = selectedTrack;
            // Update track credits when a new track is selected
            this._creditsObserver.next(this._dataStore.credits);
        });

        // Track credits stream
        this.trackCredits$ = this.credits$.map(credits => this.getTrackCredits(credits));

        // Unique credits stream
        this.uniqCredits$ = this.credits$.map(credits => this.getUniqueCredits(credits));

        // Unused credits stream
        this.unusedCredits$ = this.credits$.map(credits => {
            let uniq = this.getUniqueCredits(credits);
            let trackCreds = this.getTrackCredits(credits);
            return uniq.filter(x =>
            trackCreds.filter(z => z.partyrealid === x.partyrealid && z.instrumentcode === x.instrumentcode).length === 0);
        });
    }
  constructor(
    private zone: NgZone
  ) {
    this.window = getWindow();
    this.document = getDocument();

    const initialFocus = this.document["visibilityState"] === "visible"
      ? DetailedFocusStates.TabFocus
      : DetailedFocusStates.TabBlur;

    this.detailedFocusSubject = new BehaviorSubject<DetailedFocusStates>(initialFocus);

    // Wire up the detailed focus observable
    //
    this.detailedFocus$ = this.detailedFocusSubject
      .asObservable()
      .distinctUntilChanged();

    // Now wire up the more generic observable by mapping the detailed values to the
    //  broader ones. We also add distinct until changed because we might get both
    //  a tab and window event fired, and we don't want to emit duplicates
    //
    this.focus$ = this.detailedFocus$
      .map((focus) => {
        switch (focus) {
          case DetailedFocusStates.WindowFocus:
          case DetailedFocusStates.TabFocus:
            {
              return FocusStates.Focus;
            }
        }
        return FocusStates.Blur;
      })
      .distinctUntilChanged();


    this.zone.run(() => {

      this.document.addEventListener("visibilitychange", () => {
        if (document.visibilityState === "visible") {
          this.detailedFocusSubject.next(DetailedFocusStates.TabFocus);
        } else {
          this.detailedFocusSubject.next(DetailedFocusStates.TabBlur);
        }
      });

      /////////////////////////////////////////
      // check if browser window has focus		
      let notIE = (this.document.documentMode === undefined),
        isChromium = this.window.chrome;

      if (notIE && !isChromium) {

        // checks for Firefox and other  NON IE Chrome versions
        this.window.on("focusin",
          () => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);

            },
              300);

          });

        this.window.on("focusout", () => {
          this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);

        });

      } else {

        // checks for IE and Chromium versions
        if (this.window.addEventListener) {

          // bind focus event
          this.window.addEventListener("focus", (event: any) => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
            },
              300);

          },
            false);

          // bind blur event
          this.window.addEventListener("blur", (event: any) => {
            this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
          },
            false);

        } else {

          // bind focus event
          this.window.attachEvent("focus", (event: any) => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
            },
              300);

          });

          // bind focus event
          this.window.attachEvent("blur", (event: any) => {
            this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
          });
        }
      }
    });
  }
Example #12
0
// #docregion Observable
import {Observable, Subscriber} from 'rxjs/Rx';
import 'rxjs/add/operator/map';

var obs = new Observable<number>((obs: Subscriber<any>) => {
  var i = 0;
  setInterval(() => obs.next(++i), 1000);
});
obs.map((i: number) => `${i} seconds elapsed`).subscribe(msg => console.log(msg));
// #enddocregion
Example #13
0
function mapFilterTest(observable: Observable<number>): Observable<number> {
  return observable
    .map(value => value * 10)
    .filter(value => value > 10);
}
 constructor() {
   this.keynoteState$
     .map((state:KeynoteState) => state.status)
     .subscribe(status => this.status = status)
 }