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

json breadcrumb/path #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

json breadcrumb/path #6

wants to merge 2 commits into from

Conversation

qoby
Copy link

@qoby qoby commented Dec 1, 2014

This creates a json path, as knowing where you are in an object can be very important.

let obj = { first: second: third: fourth: true };

whenTraverse(obj, 
  enter: function(node, key, parentNode, path) {
      console.log(path);
  });

would output:

['first']
['first', 'second']
['first', 'second', 'third']
['first', 'second', 'third', 'fourth']

Not tested very thoroughly, just wanted to get it out to see if it would stick and because I need the functionality right now.

On another note, is there any reason you don't just bind a context object to each function?

context = { parentNode, key, ... }
promise.bind(context)

This way, the function argument could be the node as it currently is, and each chained promise would be returning only what it received:

.then( function(node) { return node; } )

Other properties would be available as this.parentNode, etc.

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

Successfully merging this pull request may close these issues.

1 participant