Isometrica / sub-stance

An angular-meteor subscription manager with substance.
GNU Affero General Public License v3.0
1 stars 0 forks source link

SubStance

An angular.js service that creates and maintains Meteor.js subscriptions across state transitions.

Benefits

Usage

Declare subscriptions required for your states:

.state('bookshop', {
  url: '/books/:bookId/:sort',
  templateUrl: ...,
  data: {
    $subs: [
      { name: 'books', args: ['sort'] },
      'favorites'
    ]
  }
});

Configure components that need certain subscriptions to function:

app.directive('commentsList', function($subs) {
    return {
    controller: function($scope, $element, $attrs, $transclude) {
      ...
      $subs.needsBind($scope, 'comments', $scope.someParam);
    }
  };
});

app.service('singleton', function($subs) {
  var descriptor = $subs.need('something');
  ...
  ...
  descriptor.stop();
});

Additional features:

Problem Domain

In states
...
.state('module', {
  url: '/module/:moduleId',
  parent: 'organisation',
  abstract: true,
  template: '<ui-view/>',
  resolve: {
    moduleSub: function($meteor) {
      return $meteor.subscribe('modules');
    },
    ... Other resolves
  },
  onExit: function(moduleSub) {
    moduleSub.stop();
  }
});

Problems:

In controllers
function AddressBookController($scope, $rootScope, $state, $modal, $meteor, organisation) {
  $scope.$meteorSubscribe('profileImages');
  ...

Problems:

Ad-hoc
...
if (scope.type === 'Contact') {
  scope.$meteorSubscribe('contacts');
  scope.user = scope.$meteorObject(Contacts, scope.userId);
}
...

Problems:


...
.state('overview', {
  ...
  // Boilerplate
  resolve : {
    modulesSub: function($meteor) {
      return $meteor.subscribe('modules');
    }
  },
  onExit: function(modulesSub) {
    modulesSub.stop();
  }
})
.state('module', {
  ...
  // Boilerplate
  resolve: {
    moduleSub: function($meteor) {
      return $meteor.subscribe('modules');
    },
    module: function($meteor, $stateParams, moduleSub) {
      return Modules.findOne($stateParams.moduleId);
    }
  },
  onExit: function(moduleSub) {
    moduleSub.stop();
  }
});

 Questions

 Requirements

References

Main Dependencies