Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Update hyperdiff dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 27, 2017
1 parent 80e45b6 commit a528903
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![NPM Status](https://img.shields.io/npm/dm/redis-diff.svg?style=flat-square)](https://www.npmjs.org/package/redis-diff)
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/Kikobeats)

> Perform a diff comparison backed by redis.
> Perform a difference comparison backed by redis.
## Install

Expand All @@ -25,26 +25,26 @@ const noop = () => {}
diff.set({
key: 'mykey',
value: [
{foo: 'bar'},
{foo: 'barz'},
{foo: 'baaz'}
{id: 1, foo: 'bar'},
{id: 1, foo: 'barz'},
{id: 1, foo: 'baaz'}
]
}, noop)

diff.compare({
key: 'mykey',
value: [
{foo: 'bar'},
{foo: 'baarz'},
{foo: 'bax'}
{id: 1, foo: 'bar'},
{id: 1, foo: 'baarz'},
{id: 1, foo: 'bax'}
],
id: 'foo'
ids: ['id', 'foo']
}, console.log)

// {
// added: [ { foo: 'baarz' }, { foo: 'bax' } ],
// removed: [ { foo: 'barz' }, { foo: 'baaz' } ],
// common: [ { foo: 'bar' } ]
// added: [ { id: 1, foo: 'baarz' }, { id: 1, foo: 'bax' } ],
// removed: [ { id: 1, foo: 'barz' }, { id: 1, foo: 'baaz' } ],
// common: [ { id: 1, foo: 'bar' } ]
// }
```

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ function createDiff (opts) {
}

function compare (opts, cb = noop) {
const {key, value, id} = opts
const {key, value, ids} = opts
if (!exists(key)) return cb(TypeError('Need to provide a key.'))
if (!exists(value)) return cb(TypeError('Need to provide a value.'))
if (!exists(id)) return cb(TypeError('Need to provide a id.'))
if (!exists(ids)) return cb(TypeError('Need to provide a id.'))

get({key}, function (err, data) {
if (err) return cb(err)
return cb(null, diff(data, value, id))
return cb(null, diff(data, value, ids))
})
}

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
},
"keywords": [
"array",
"collection",
"compare",
"diff",
"difference",
"memory",
"redis"
],
"dependencies": {
"hyperdiff": "~1.0.0",
"hyperdiff": "~2.0.1",
"json-future": "~2.0.1",
"redis": "~2.6.3"
},
Expand Down
21 changes: 10 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const createDiff = require('..')

const FIXTURE = {
FIRST: [
{foo: 'bar'},
{foo: 'barz'},
{foo: 'baaz'}
{id: 1, foo: 'bar'},
{id: 1, foo: 'barz'},
{id: 1, foo: 'baaz'}
],
SECOND: [
{foo: 'bar'},
{foo: 'baarz'},
{foo: 'bax'}
{id: 1, foo: 'bar'},
{id: 1, foo: 'baarz'},
{id: 1, foo: 'bax'}
]
}

Expand Down Expand Up @@ -44,13 +44,12 @@ describe('redis-diff', function () {
diff.compare({
key: 'mykey',
value: FIXTURE.SECOND,
id: 'foo'
ids: ['id', 'foo']
}, function (err, result) {
console.log(result)
should(err).be.null()
result.added.should.be.eql([{ foo: 'baarz' }, { foo: 'bax' }])
result.removed.should.be.eql([{ foo: 'barz' }, { foo: 'baaz' }])
result.common.should.be.eql([{ foo: 'bar' }])
result.added.should.be.eql([{ id: 1, foo: 'baarz' }, { id: 1, foo: 'bax' }])
result.removed.should.be.eql([{ id: 1, foo: 'barz' }, { id: 1, foo: 'baaz' }])
result.common.should.be.eql([{ id: 1, foo: 'bar' }])
done()
})
})
Expand Down

0 comments on commit a528903

Please sign in to comment.