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

ng-identity-map

v0.1.0

Published

An Identity Map implementation for push-based AngularJS applications.

Downloads

2

Readme

ng-identity-map

An Identity Map implementation for push-based AngularJS applications. Not to be confused with angular-identity-map. For a discussion detailing some of the philosophical differences between these implementations, please see https://github.com/dbaumann/angular-identity-map/pull/1.

Why?

Because a large $scope is a challenge to maintain. This is particularly true if you're trying to find and mutate objects in response to server side activity. Here we solve this problem using the Identity Map pattern.

Additionally, large applications inevitably involve a lot of customized behavior in the form of functions which end up somewhere in $scope. The object oriented way to keep such complexity in check is to define the behavior on the objects, or in javascript, on their prototypes. However once this is done, the objects become difficult to mutate without disturbing their prototypical nature. For this, an IdentityMap.update method is provided, which makes use of traverse to specify path-based mutations on deeply nested objects in a manner similar to functional lenses.

Requirements

traverse

Usage

App

var myAppModule = angular.module("MyApp", ["dbaumann.identity-map"]);

myAppModule.controller("myController", function($scope, IdentityMap, Phone, PhoneImage, myService) {
  $scope.phoneList = [
    new Phone({
      id: 1,
      name: "Dell Streak 7",
      images: [
        new PhoneImage({id: 1, name: "7.0", imagePath: "img/phones/dell-streak-7.0.jpg"})
      ]
    })
  ];

  myService.receive("PhoneUpdate", function(event) {
    var existingPhone = IdentityMap.get(Phone)(event.phone);
    // ... now you can mutate the model in $scope which corresponds to event.phone

    // or update the whole thing using IdentityMap
    var updatedPhone = IdentityMap.update(Phone, ["images"])(event.phone);

    // or update specific parts
    val updateNameAndPath = IdentityMap.update(PhoneImage, ["name", "imagePath"]);
    event.phone.images.map(function(image) {
      updateNameAndPath(image);
    });

    // or use a lens (note the nested array - this is where traverse is used)
    val updatedPhoneFirstImagePath = IdentityMap.update(Phone, [["images", 0, "imagePath"]])(event.phone);
  });
});

myAppModule.factory("myService", function(/* deps */) {
  return {
    recieve: function(messageType, callback) { /* ... some async code invoking callback */ }
  }
};

myAppModule.factory("Phone", function(/* deps */) {
  function Phone(attrs) {
    for (k in attrs) { this[k] = attrs[k] }
    // store in the map; all future calls with the same parameters will have no effect on the map
    // if you really need to replace, use IdentityMap.replace
    IdentityMap.set(this.constructor)(this);
  }

  // required by IdentityMap, otherwise an Error is thrown
  // must be something immutable and unique
  Phone.prototype.identity = function() { return this.id; };

  return Phone;
};

myAppModule.factory("PhoneImage", function(/* deps */) {
  function PhoneImage(attrs) {
    for (k in attrs) { this[k] = attrs[k] }
    IdentityMap.set(this.constructor)(this);
  }

  PhoneImage.prototype.identity = function() { return this.id; };

  return PhoneImage;
};

Configuration

Nothing to configure (yet).

More examples can be found in test/spec/tests.js.

Development

Code quality is ensured with CoffeeScript, CoffeeLint, and Karma.

npm install -g grunt-cli
npm install && bower install
grunt

Live Reloading

grunt karma:unit:start watch

Build

grunt dist