1.0.1 • Published 10 years ago
sticky-identity v1.0.1
sticky-identity
Transformware that maintains consistent object identity when using a sticky datastore.
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