JSPM

hyperobj-context

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q30123F
  • License MIT

Nested hyperscript contexts for hyperobj

Package Exports

  • hyperobj-context

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hyperobj-context) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hyperobj-context

Nested hyperscript contexts for hyperobj

const hs = require('hyperscript-nested-contexts')(require('hyperscript'))
const ho = require('hyperobj-context')(require('hyperobj'), hs)
const observable = require('observable')

const render = ho(
  function(v) {
    if (typeof v!=='object') return
    const h = this.ctx || hs
    return h('ol',
      Object.keys(v).map( (k)=> {
        const msg = observable()
        return ((h)=>{
          msg('clickme')
          return h('li', [
            h('em.key', h('span', msg), this.call(this, k), {
              onclick: function() {
                msg('I was clicked')
                h.cleanup()
              }
            }),
            h('span.value', this.call(this, v[k], k))
          ])
        })(this.pushContext(h.context()))
        this.popContext()
      })
    )
  },
  function(v) {
    const h = this.ctx || hs
    return h('span.string', v)
  }
)

document.body.appendChild(
  render(require('./package.json'))
)