Skip to content

Dynamic argument #15

@jongacnik

Description

@jongacnik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions