Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bvalosek/sticky-identity
Maintain consistent object identity when using a sticky datastore
https://github.com/bvalosek/sticky-identity
Last synced: 10 days ago
JSON representation
Maintain consistent object identity when using a sticky datastore
- Host: GitHub
- URL: https://github.com/bvalosek/sticky-identity
- Owner: bvalosek
- License: mit
- Created: 2014-06-02T01:38:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-02T01:54:30.000Z (over 10 years ago)
- Last Synced: 2024-11-30T00:51:51.180Z (27 days ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# sticky-identity
[![Build Status](https://travis-ci.org/bvalosek/sticky-identity.png?branch=master)](https://travis-ci.org/bvalosek/sticky-identity)
[![NPM version](https://badge.fury.io/js/sticky-identity.png)](http://badge.fury.io/js/sticky-identity)Transformware that maintains consistent object identity when using a
[sticky](https://github.com/bvalosek/sticky) datastore.[![browser support](https://ci.testling.com/bvalosek/sticky-identity.png)](https://ci.testling.com/bvalosek/sticky-identity)
## Installation
```
$ npm install sticky-identity
```## Usage
Assuming we have a [sticky](https://github.com/bvalosek/sticky) `Datastore` as
`db` and some sourced repository for the `User` model:```javascript
var identity = require('sticky-identity');db.use(User, identity());
```Model identity is consistent now across all calls.
```javascript
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:```javascript
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