HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Open source angularjs pouchdb model persistence layer - release ready?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
angularjslayerpouchdbsourceopenreadyreleasemodelpersistence

Problem

I'm considering releasing a library as a bower module. Are there issues with code quality, missing test cases, that need to be addressed first? Perhaps it's not a good candidate for public release. If so, why not?

What level of documentation would you want for something like this? I've seen some open source modules publish annotated source, in addition to API documentation. Is annotated source documentation overkill for something like this?

Library Details:

  • The library provides a simple object persistence layer for Angularjs apps using a local Pouchdb database. It is $digest aware and promise based. The public API consists of



  • setType(type, fn) //register prototype



  • newObj() //new object from registered prototype



  • saveObj(obj) // insert and update



  • getAll(type)



  • getById(type,id)



  • getByName(type,name)



  • getByGQL(query) //TODO: support arbitrary find conditions via Google Query Language



  • deleteObj(obj)



  • deleteById(id)



  • Because the library supports objects that may include functions, the library requires a prototype for each type be registered with the library. The prototype is used to re-hydrate de-serialized objects retrieved from the database.



  • Evil new Function() calls are slated to be eliminated by replacing view based queries with their equivalent GQL queries.



  • Models are required by Pouchdb to have _id and _rev properties. _id is unique within a database.



  • Models are required by the library to have type and name properties. Currently name is enforced to be unique within type. However, the name constraint is slated to be removed in favor of an available unique model validation, allowing any property to act as a unique key.



  • Model validation support will include all of validatejs's ActiveRecord style constraints, plus library specific unique, exists and notExists constraints.



Sample Code (implements the save/update operations):

```
// save or update an object, returns a promise -- ex

Solution

The code looks good (make sure to replace new Function quickly :), and it's a great candidate for a public release.

It is short enough to deserve annotated documentation that would explain how it works which is useful for debugging. But that should not replace the actual API documentation.

Context

StackExchange Code Review Q#37161, answer score: 2

Revisions (0)

No revisions yet.