Skip to content
This repository has been archived by the owner on Mar 2, 2018. It is now read-only.

alibaba-archive/ng-warehouse

Repository files navigation

ng-warehouse v0.2.0 Build Status

A data cache with events for AngularJS.

DEMO

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

  }]);

Installation

Bower:

bower install ng-warehouse
<script src="/pathTo/jsonkit/jsonkit.js"></script>
<script src="/pathTo/ng-warehouse/index.js"></script>

API

var cache = warehouse(namespace);

warehouse(namespace)

warehouse(namespace, store2)

warehouse.getAll()

cache.has(key)

cache.get(key)

cache.getAll()

cache.set(key, value[, silent])

cache.add(key, value[, silent])

cache.remove(key[, silent])

cache.bind(scope, type, listener)

cache.destroy()

About

A data cache with events for AngularJS

Resources

License

Stars

Watchers

Forks

Packages

No packages published