Giter VIP home page Giter VIP logo

factoryng's Introduction

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?

factoryng's People

Contributors

redgeoff avatar

Watchers

Nolan Lawson avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.