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

What's a good way to deal with deeply nested cursors? #17

Closed
bebraw opened this issue Apr 20, 2015 · 6 comments
Closed

What's a good way to deal with deeply nested cursors? #17

bebraw opened this issue Apr 20, 2015 · 6 comments
Labels

Comments

@bebraw
Copy link
Contributor

bebraw commented Apr 20, 2015

I have a tree like this:

const tree = new Baobab({
  lanes: []
}, {
  validate: {
    lanes: [{
      id: 'number',
      name: 'string',
      notes: [
        {
          id: 'number',
          task: 'string',
        }
      ]
    }]
  }
});

It is possible the tree will grow further as I add new concepts to the system (maybe boards etc.).

So far the decorator syntax has worked just fine. I feel it gets a little cumbersome on the lower levels of the hierarchy, though. To point at notes I would have to do something like this:

@branch({
  cursors: function() {
    return {
      note: ['lanes', this.props.laneIndex, 'notes', this.props.noteIndex],
    };
  }
})
...

Maybe the cursor of previous level could be passed instead of root to the child instead? Then I could do:

// XXX: this should point to lanes cursor, not root to work! Needs to be passed as a prop?
@branch({
  cursors: function() {
    return {
      note: ['notes', this.props.noteIndex],
    };
  }
})
...

If I could do this, I wouldn't have to care about the whole hierarchy, just the immediate parent.

How would you deal with deep nesting like this?

@Yomguithereal
Copy link
Owner

This is an interesting use case. I am think of a possibility to do something like this through props or context but need to think this a little bit more because cases when this would not be as simple. What you can do in the meantime is to pass the base of the path as a prop, for instance.

On a side note, you seem to be using baobab@0.4.4 here whereas this repo deals with baobab@1.0.0 version. There is a baobab@1.0.0-rc1 available on npm and I will soon release v1.

@bebraw
Copy link
Contributor Author

bebraw commented Apr 20, 2015

@Yomguithereal Cool. I'll go with props.

@bebraw
Copy link
Contributor Author

bebraw commented May 9, 2015

@Yomguithereal I've been thinking this a bit more. It seems to me that in my case the smartest move would be to flatten the structure (notes and lanes and root level) and provide facets.

Related: Yomguithereal/baobab#225.

@Yomguithereal
Copy link
Owner

I was thinking about this lately but I guess I'll see how cerebral fix the problem.

@bebraw
Copy link
Contributor Author

bebraw commented Sep 28, 2015

@Yomguithereal Yeah, apparently monkeys solve this neatly. There's a WIP demo.

@Yomguithereal
Copy link
Owner

Cool. Will check this out asap.

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

No branches or pull requests

2 participants