Transformware that maintains consistent object identity when using a sticky datastore.
$ npm install sticky-identity
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 = '[email protected]';
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.
$ npm test
MIT