Skip to content

bvalosek/sticky-identity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Maintain consistent object identity when using a sticky datastore

Resources

License

Stars

Watchers

Forks

Packages

No packages published