Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having trouble understanding how the prefilter should work #34

Closed
tnrich opened this issue Jan 12, 2015 · 2 comments
Closed

Having trouble understanding how the prefilter should work #34

tnrich opened this issue Jan 12, 2015 · 2 comments

Comments

@tnrich
Copy link

tnrich commented Jan 12, 2015

I am a little bit confused by the documentation of the pre-filter functionality.

At one point in the readme, it says:
"Diff arguments:
prefilter - an optional function that determines whether difference analysis should continue down the object graph."

And,
"Pre-filtering Object Properties
The prefilter's signature should be function(path, key) and it should return a truthy value for any path-key combination that should be filtered. If filtered, the difference analysis does no further analysis of on the identified object-property path."

But there is no actual instance of a diff that uses the pre-filter in the readme or examples that I could find. Something showing exactly how to use the following function would be great!

diff.diff(lhs, rhs, function (path, key) {
    //logic
    }
});

The only thing I could find was:

observableDiff(lhs, rhs, function (d) {
    // Apply all changes except those to the 'name' property...
    if (d.path.length !== 1 || d.path.join('.') !== 'name') {
        applyChange(lhs, rhs, d);
    }
});

Which isn't the diff.diff method for one, and doesn't take in two arguments for another.

Awesome package and thanks!

@flitbit
Copy link
Collaborator

flitbit commented Jan 13, 2015

The readme could use some more detail.

Take a look at the tests, a prefilter tests whether the item at the path and key should be filtered. Any truthy result will cause diff to filter the item.

There are several examples in the tests.

The observableDiff function is an underlying function, the 3rd param is the observer which is called for each difference detected. If you want to call observableDiff, the 4th parameter is the prefilter.

@flitbit flitbit closed this as completed Jan 13, 2015
@tnrich
Copy link
Author

tnrich commented Jan 13, 2015

Awesome, thanks for the feedback. I took a look at the test and it cleared
up using a prefilter with a key. I'll investigate using a prefilter with a
path too since that's the actual operation I want to do.

Cheers,
Thomas

On Mon, Jan 12, 2015, 7:49 PM Phillip Clark notifications@github.com
wrote:

The readme could use some more detail.

Take a look at the tests
https://github.com/flitbit/diff/blob/1bd7cfc7e94a6339568c14046e9eeb205d2a7b7c/test/tests.js#L180-183,
a prefilter tests whether the item at the path and key should be
filtered. Any truthy result will cause diff to filter the item.

There are several examples in the tests.

The observableDiff function is an underlying function, the 3rd param is
the observer which is called for each difference detected. If you want
to call observableDiff, the 4th parameter is the prefilter

diff/index.js

Line 82 in 1bd7cfc

function deepDiff(lhs, rhs, changes, prefilter, path, key, stack) {

.


Reply to this email directly or view it on GitHub
#34 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant