nanopage
nanopage copied to clipboard
Use key as url if unavailable
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.
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):
- 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
}
- 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
}
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.