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

Dynamic argument #15

Open
jongacnik opened this issue May 20, 2018 · 0 comments
Open

Dynamic argument #15

jongacnik opened this issue May 20, 2018 · 0 comments

Comments

@jongacnik
Copy link
Collaborator

Allow a second argument into page to define a dynamic/fallback content entry. Example in context of choo:

var page = require('nanopage')

var p = page(state.href, {
  source: `/bundles/${state.params.id}.json`,
  loaded: false
})

This allows for pages to be added dynamically to state. Logic under the hood is something like:

function page (key, dynamic) {
  var content = state.content[key]
  
  if (!content && dynamic) {
    state.content[key] = dynamic
    content = state.content[key]
  }

  return content
}

That second param could also be a function:

var p = page(state.href, key => ({
  source: `/bundles/${state.params.id}.json`,
  loaded: false
}))

@s3ththompson

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

1 participant