sticky-identity

1.0.1 • Public • Published

sticky-identity

Build Status NPM version

Transformware that maintains consistent object identity when using a sticky datastore.

browser support

Installation

$ npm install sticky-identity

Usage

Assuming we have a sticky Datastore as db and some sourced repository for the User model:

var identity = require('sticky-identity');
 
db.use(User, identity());

Model identity is consistent now across all calls.

var user = new User();
user.email = 'awesome@cool.net';
db.add(User)(user)
  .then(function(u) {
    u === user; // true
    return db.get(User)(user.id);
  })
  .then(function(u) {
    u === user; // true
  });

Identity is checked via the id parameter by default, but can be determined by any string-like return value from a function argument:

db.user(User, identity(function(x) { return x._id; }));

Keep in mind that the memory usage of this transformware will scale as the number ofunique objects that are output or input into the repository grows.

Testing

$ npm test

License

MIT

Package Sidebar

Install

npm i sticky-identity

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bvalosek