A data cache with events for AngularJS.
angular.module('demoApp', ['data.warehouse'])
.controller('DemoCtrl', ['$scope', 'warehouse', 'store2', function ($scope, warehouse, store2) {
// use localStorage with [store2](http://github.com/nbubna/store)
var articleCache = warehouse('users', store2);
// or user memory cache
var userCache = warehouse('users');
$scope.userList = userCache.getAll();
$scope.articleList = articleCache.getAll();
userCache.bind($scope, 'add', function (userId, user) {
$scope.userList.push(user);
if (!$scope.$$phase) $scope.$apply();
});
articleCache.bind($scope, 'add', function (articleId, article) {
$scope.articleList.push(article);
if (!$scope.$$phase) $scope.$apply();
});
//...more
}]);
Bower:
bower install ng-warehouse
<script src="/pathTo/jsonkit/jsonkit.js"></script>
<script src="/pathTo/ng-warehouse/index.js"></script>
var cache = warehouse(namespace);