Skip to content

Commit

Permalink
use deep equal for equality checking objects
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8890 committed Aug 24, 2015
1 parent 9f19c3d commit d65456b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/adapter/adapters/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import deepEqual from 'deep-equal'
import { toBuffer } from 'array-buffer'
import * as keys from '../../common/keys'
import { BadRequestError } from '../../common/errors'
import deepEqualOptions from '../../common/deep_equal_options'


export function applyOptions (count, fields, records, options) {
Expand Down Expand Up @@ -46,7 +48,7 @@ export function applyOptions (count, fields, records, options) {
const matchCheck = new WeakMap([
[ Date, (a, b) => a.getTime() === b.getTime() ],
[ Buffer, (a, b) => a.equals(toBuffer(b)) ],
[ Object, () => false ]
[ Object, (a, b) => deepEqual(a, b, deepEqualOptions) ]
])


Expand Down Expand Up @@ -74,6 +76,7 @@ function matchByField (fields, match, record) {
}


// For comparing sort order.
const comparisons = new WeakMap([
[ Number, (a, b) => a - b ],
[ String, (a, b) => a < b ? -1 : a > b ? 1 : 0 ],
Expand Down
1 change: 1 addition & 0 deletions lib/common/deep_equal_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { strict: true }
3 changes: 2 additions & 1 deletion lib/dispatch/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as methods from '../common/methods'
import * as keys from '../common/keys'
import { NotFoundError, BadRequestError } from '../common/errors'
import { find, includes } from '../common/array_proxy'
import deepEqualOptions from '../common/deep_equal_options'


/**
Expand Down Expand Up @@ -61,7 +62,7 @@ export default function (context) {
return Promise.resolve(transform && transform.input ?
transform.input(context, clone(record), update) : update)
.then(update => {
if (!deepEqual(update, cloneUpdate, { strict: true }))
if (!deepEqual(update, cloneUpdate, deepEqualOptions))
context.response.updateModified = true

transformedUpdates.push(update)
Expand Down

0 comments on commit d65456b

Please sign in to comment.