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

Use key as url if unavailable #6

Open
jondashkyle opened this issue Apr 20, 2018 · 2 comments
Open

Use key as url if unavailable #6

jondashkyle opened this issue Apr 20, 2018 · 2 comments

Comments

@jondashkyle
Copy link
Owner

The new pages regex checks against a key named url to find children. This is fine when using with something like hypha as it defines a url key in each page object. Would be cool to fallback to the page key name somehow if that url is unavailable, but gets a little tricky with how value is continually set as methods are called with function chainability.

Anyway, quick though and dropping here to think about later.

@jongacnik
Copy link
Collaborator

Yea I was already thinking about this! Using url feels really fragile and would much rather use key. I could see this working a couple ways. Demonstrating here with v psuedo code (imagine this making sense in the context of the class):

  1. Store a reference to the current _key, in addition to _state and _value
function page (key) {
  this._key = key
  this._value = this._state[key]
}

function children () {
  var children = // regex using `this._key`
  return children
}
  1. Store an object rather than just the value when looking up a page:
function page (key) {
  this._value = {
    [key]: this._state[key]
  }
}

function children () {
  var key = Object.keys(this._value)[0]
  var children = // regex using `key`
  return children
}

@jondashkyle
Copy link
Owner Author

jondashkyle commented Apr 20, 2018

something closer to the second option might be right, as i’m unsure how we’d handle that with a heavy chain such as:

page('/example').pages().sortBy('date', 'asc').first().find('wtf').v()

that Object.keys solution seems like a bit of a hack, in that if you run children when not on a page you might get some wild results, but that might be nbd.

@jongacnik jongacnik mentioned this issue May 17, 2018
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

2 participants