Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
This repository was archived by the owner on Aug 13, 2021. It is now read-only.

Subscription to backend events doesn't work after reload #32

@ipsips

Description

@ipsips

I have built an app relying on the sails Blueprints API and the fact that:

autoSubscribe is normally set to true, which means that any time a socket request is made for a model, the requesting socket will be subscribed to all events for that model instance
stackoverflow

so i resolve the route data by making a request to sails in the route resolver and pass it (as a promise) to the route controller (which gets instantiated after the promise is resolved/rejected)... all good but $sailsSocket.subscribe('venue', …) in my controller doesn't do it's trick after i browser-reload the venue details page. (it does work after i visit other routes of my app, just not immediately after reload)

what am i missing?

angular
.module('cineApp', ['ngRoute', 'sails.io', 'eventAppControllers'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

    $locationProvider
        .html5Mode(true);

    $routeProvider
        .when('/venues/:slug', {
            templateUrl: '/templates/venue/single.html',
            controller: 'VenueDetailsController',
            resolve: {
                'venueData': function($sailsSocket, $q, $route) {

                    var deferred = $q.defer();

                    $sailsSocket
                        .get('/api/venue/'+$route.current.params['slug'])
                        .success(function(data, status, headers, config) {

                            deferred.resolve(data);

                        });

                    return deferred.promise;

                }
            }
        })
        .otherwise({
            templateUrl: '/templates/error404.html',
            controller: 'Error404Controller'
        });

}]);


angular.module('eventAppControllers', [])
.controller('VenueDetailsController', ['$scope', '$sailsSocket', '$route', '$location', 'venueData', function($scope, $sailsSocket, $route, $location, venueData) {

    $scope.venueData = venueData ? venueData : null;

    //  Subscribe to changes
    //——————————————————————————————
    $sailsSocket.subscribe('venue', function(res){

        if ( res.verb == 'updated' ) {

            if ( 'slug' in res.data )
                $location.path('/venues/'+ res.data.slug);

            $route.reload();

        }

        if ( res.verb == 'destroy' )
            $route.reload();

    });

}]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions