npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bedrock-angular-resource

v3.0.3

Published

A bedrock AngularJS module that provides services for managing resources and handling resources refreshing.

Downloads

5

Readme

bedrock-angular-resource

A bedrock AngularJS module that provides services for managing resources and handling resources refreshing.

brResourceService provides a Collection class that can be used to access a remote REST collection resource. Operations store data locally in a structure that is suitable to use as a AngularJS data source.

brRefreshService is used to manage global refresh events to keep all active collection data up to date.

Quick Examples

angular.module('example', ['bedrock.resource']).service('myService', factory);

/* @ngInject */
function factory(brRefreshService, brResourceService) {
  var service = {};

  // a collection of resources
  service.collection = new brResourceService.Collection({
    url: 'https://example.com/resources'
  });

  // register for system-wide refreshes
  brRefreshService.register(service.collection);

  return service;
}
// controller definition
function() {
  /* @ngInject */
  function factory($scope, myService) {
    // ...

    brRefreshService.register($scope, function(force) {
      var opts = {
        force: !!force,
        params: $location.search()
      };
      myService.collection.getCurrent(opts)
        .then(function(resource) {
          // update models
        })
        .catch(function(err) {
          // handle error
        })
        .then(function() {
          // update UI
          $scope.$apply();
        });
    })();
  }

  return {myController: factory};
}

Setup

bower install bedrock-angular-resource

Installation of the module followed by a restart of your bedrock server is sufficient to make the module available to your application.

To manually add bedrock-angular-resource as a dependency:

angular.module('myapp', ['bedrock.resource']);

API

brRefreshService.register([scope], fn)

Register for the scope refreshData event. scope defaults to $rootScope. If fn is a function it is called on the event. If fn is a brResourceService.Collection, then Collection.getAll({force: true}) is called.

brRefreshService.refresh()

Broadcast the refreshData event on the $rootScope.

brResourceService.Collection(config)

Config options:

  • url: url to collection (string)
  • storage: reference to external array of data (optional)
  • expires: time data expires (timestamp, optional [0])
  • maxAge: maximum cache age (ms, optional [2m])
  • query: default params object to use for getAll() (optional)
  • finishLoading: custom callback to call after every load (fn, optional)

Properties:

  • config: the config used during creation.
  • storage: the raw storage
  • expires: the expiration date
  • maxAage: the maximum cache age
  • loadingCount: the number of active loading operations
  • state: state object including current loading flag.

brResourceService.Collection.startLoading(count)

Used when internal operations start remote operations.

brResourceService.Collection.finishedLoading(count)

Used when internal operations finish remote operations. Will call the config finishedLoading callback if set.

brResourceService.Collection.getAll(options)

Load the entire collection.

brResourceService.Collection.get(resourceId, options)

Load a single resource.

brResourceService.Collection.getCurrent(options)

Load the current resource (based on $location).

brResourceService.Collection.addToStorage(resource, options)

Add a resource to local storage.

brResourceService.Collection.add(resource, options)

Add a resource to remote storage and local storage.

brResourceService.Collection.update(resource, options)

Update a resource in remote storage and local storage.

Options:

  • url: url to resource ([resource.id])
  • get: url to get resource ([options.url || resource.id])

brResourceService.Collection.del(resourceId, options)

Delete a resource in remote storage and local storage.

brResourceService.Collection.clear()

Clear all local storage.

brResourceService.Collection.setQuery(params)

Set query used for remote operations.