nguyenthong / Geo_chat

Geo_chat app( Ionic with firebase)
2 stars 6 forks source link

Rxjs problems #11

Open nguyenthong opened 9 years ago

nguyenthong commented 9 years ago

dash page controller, what is the first page applicaiton show users accessible rooms dash_controller.

var promise = RoomService.all(key, locationArr, distance, user_location, range);
var observable = rx.Observable
    .fromPromise(promise)
    .map(function (container) {
      return container.circles;
    });

  observable.subscribe(function (circles) {
    $scope.circles = circles; // the circles arrived over time, after the promises was initialized
  });

The room services is where method RoomService.all() was called and return container object room_service.js

uiGmapGoogleMapApi.then(function(maps) {
  geoQuery.on("key_entered", function(key, location, distance) {
     roomRef.child(key).once("value", function (data) {
       //todo remove this in production
       //console.log(key + " entered query at " + location + " (" + distance + " km from center)");
       //console.log(data.val());

This code query every rooms inside the 2km radius then an through the function userInCircleDetection(){} for checking the room user can access. Therefore I think the problem might be in this part, it checking every room, when it hit the first room it already return the promises

TapaniAla commented 9 years ago

I agree. If you take a look for the documentation of Firebase/Geofire it says "ready fires once when this query's initial state has been loaded from the server. The ready event will fire after all other events associated with the loaded data have been triggered. ready will fire again once each time updateQuery() is called, after all new data is loaded and all other new events have been fired."

nguyenthong commented 9 years ago

I am trying to find the way to turn those multiple callback into series of event stream. Maybe it could solve this problem.