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

factoryng

v0.0.11

Published

An all-in-one angularjs factory that wraps multiple backends

Downloads

8

Readme

factoryng

Build Status

An all-in-one angularjs factory that wraps multiple backends.

Why?

AngularJS is great and there are tons of amazing backends like pouch, firebase, etc... Unfortunately, some of your backend's structure ultimately leaks into your angular controllers. This means that your controllers are then tightly coupled with your backend, which makes it difficult to switch your backend without modifying your controllers.

With factoryng, you can feel free to develop your controllers with little regard to your backend. If you choose to switch backends, include a new backend or use multiple backends you don't have to worry about rewriting your controllers. Sure, your current backend works great for you now, but will it still be your top choice in 6 months?

Live Demo: Projects (Kitchen Sink)

Projects Demo

Live Demo: Contacts (Simple Example)

Contacts Demo

And, the Contacts Demo Source Code

Usage

Download via bower

bower install factoryng

Download via npm

npm install factoryng

Include the scripts

You must include factoryng.js, any adapters that you are using and any underlying adapter technologies, e.g.

<script src="bower_components/factoryng/dist/factoryng.min.js"></script>

<script src="//cdn.jsdelivr.net/pouchdb/3.0.5/pouchdb.min.js"></script>
<script src="bower_components/factoryng/dist/adapters/pouchyng.min.js"></script>

<script src="//cdn.firebase.com/js/client/1.0.21/firebase.js"></script>
<script src="bower_components/factoryng/dist/adapters/firyng.min.js"></script>

API

Let Adapter be the adapter, e.g. Pouchyng, DeltaPouchyng, Firying, etc...

Instantiate

var adapter = new Adapter(name[, url, sortBy]);

e.g.

var adapter = new Adapter('todos', 'http://127.0.0.1:5984', yngutils.ASC);

or:

var adapter = new Adapter('todos', 'http://127.0.0.1:5984', function (a, b) {
  return a.someAttr - b.someAttr;
});

Bind

adapter.bind(scope);

e.g.

// Bind to $scope and load all docs
adapter.bind($scope).then(function () {
  console.log('done binding');
  console.log($scope.todos);
  // $scope.todos[0] = adapter.at(0)
  // $scope.todos[0].$id = the unique id of the doc
  // $scope.todos[0].$priority = the priority/order of the doc
});

Create Doc

adapter.create(doc);

e.g.

adapter.create(doc).then(function(createdDoc) {
  console.log('done creating doc');
  // createdDoc.$id = the unique id of the new doc
});

Update Doc

adapter.update(doc);

e.g.

adapter.update(doc).then(function (updatedDoc) {
  console.log('done updating doc');
  // updatedDoc.$id = the unique id of the updated doc
});

Prioritize/Order Doc

adapter.setPriority(docOrId, priority);

e.g.

adapter.setPriority('123', 4).then(function (updatedDoc) {
  console.log('done setting priority');
  // updatedDoc.$id = the unique id of the updated doc
  // adapter.get('123').$priority = 4
});

Remove Doc

adapter.remove(docOrId);

e.g.

adapter.remove(docOrId).then(function (deletedDoc) {
  console.log('done removing');
  // deletedDoc.$id = the unique id of the updated doc
});

For Each

adapter.forEach(callback[, thisArg]);

e.g.

adapter.forEach(function (element, index, array) {
  console.log('a[' + index + '] = ' + element);
});

At

adapter.at(index);

e.g.

adapter.at(0); // first doc
adapter.at(1); // second doc

Get

adapter.get(id);

e.g.

adapter.get('123'); // get doc with $id = '123'

Contributing

A few adapters have already been written. Is yours missing? Can you help us write it?