Skip to content

Commit

Permalink
✨ subscription shape
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Aug 8, 2019
1 parent e988c49 commit 0c3b207
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"bundlesize": [
{
"path": "dist/final-form.umd.min.js",
"maxSize": "5.0kB"
"maxSize": "5.02kB"
},
{
"path": "dist/final-form.es.js",
Expand Down
40 changes: 35 additions & 5 deletions src/subscriptionFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,45 @@ export default function<T: { [string]: any }>(
keys.forEach(key => {
if (subscription[key]) {
dest[key] = src[key]
if (
!previous ||
(~shallowEqualKeys.indexOf(key)
? !shallowEqual(src[key], previous[key])
: src[key] !== previous[key])
if (!previous) {
different = true
} else if (
~shallowEqualKeys.indexOf(key) &&
!shallowEqual(src[key], previous[key])
) {
different = true
} else if (
~['values', 'value'].indexOf(subscription[key]) &&
'object' === typeof subscription[key]
) {
if (previous[key] && src[key]) {
different = checkDiffByShape(
src[key],
previous[key],
subscription[key]
)
} else {
different = src[key] !== previous[key]
}
} else if (src[key] !== previous[key]) {
different = true
}
}
})
return different
}

function checkDiffByShape(a, b, shape) {
let different = false
Object.keys(shape).forEach(k => {
if (different) {
return
}
if ('object' === typeof shape[k]) {
different = different || checkDiffByShape(a[k], b[k], shape[k])
} else {
different = different || !shallowEqual(a[k], b[k])
}
})
return different
}

0 comments on commit 0c3b207

Please sign in to comment.