-
Notifications
You must be signed in to change notification settings - Fork 64
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
Pull parsing and Stream API support #44
Comments
The |
Well, there is no streaming specifically. |
I was thinking more along the lines of: var iterator = JsonRefs.findRefIterator(json);
function getNextRef () {
var ref = iterator.next();
if (ref && meetsCondition(ref)) {
JsonRefs.resolveRefIn(ref, json).then(function () {
getNextRef(); // Or we could conditionally call this upon a new event, say such
// as when the user clicks to expand the rendered JSON in view
});
}
} This avoids checking the entire JSON file instead of merely avoiding returning certain results. |
The new version of JsonRefs.findRefs({...}, {
filter: function (refDetails, path) {
return meetsCondition(refDetails));
}
}); That's not an exact example but the idea is there. For each valid JSON Reference, the https://github.com/whitlockjc/json-refs/blob/master/docs/API.md#module_JsonRefs..RefDetailsFilter |
That's good to know but it won't quite meet my needs as I'd like to avoid traversing the whole document (unless and until needed). Are you open to a PR for this iterator idea whenever I may get around to it (i.e., and leave the issue open even if not making it into 2.0.0)? |
If I understand, you just need an "out" when parsing to stop processing. Other than that, the current |
As for PRs, I'm always open to them. |
Yes, having an "out" but also having a "resume", so one can pick up the iteration again if and when desired (without the consumer needing to care or manage where we are exactly in the JSON object tree as your library would keep track of that for us). I think an iterator is the most common and convenient way for this kind of thing to be done. Does that make sense? |
It makes sense. I'll likely not put any time into this until |
Ok, very cool, thanks! |
And for my or others' reference, I see we might use the Iterator protocol and optionally with a polyfill if you wish to maintain compatibility with older browser. |
Btw, it seems that ES6 generators provide for a particularly elegant implementation of such iterators. Would you be amenable (if I find the energy) to my modifying the json-refs code (if not also the path-loader code), putting in a babel routine to convert ES6 back to ES5 until ES6 is more widely supported? |
If I had to guess, I'd think that moving to ES6 would likely happen after the initial |
Edited the OP to indicate a desire to see multiple strategies for the iterator if possible. Plan to get to your other items within the day. |
FWIW--and I haven't looked at your code carefully---the thought occurred to me that if possible, it may be helpful to use a generic JSON iterator (such as https://github.com/Floby/node-object-iterator/ ) to do the traversing, though an iterator which could jump ahead by type (e.g., object) and filter (e.g., only with |
Hi,
The approach I envision for a pull parser would be:
The use cases I have in mind:
$.aProperty.anotherProperty
, there may be no need for loading all of the JSON References in the document (e.g., within a$.aThirdProperty
branch), so as JSONPath is traversing the JSON object to find the path, it will only resolve references (and any descendant references) if they are encountered along the way of searching for the user-specified path.Ideally an iterator (finding or resolving) could follow any of these strategies:
Given the increase of availability of streams, and the potential for applications such as chat, relying on them, I'd also like to see Streams API support go along with this request, at least being anticipated if browser adoption is too low to justify support now (unless an existing streams API matches the planned one).
The text was updated successfully, but these errors were encountered: