4.1.0 • Published 4 years ago

marycat v4.1.0

Weekly downloads
9
License
ISC
Repository
github
Last release
4 years ago

Marycat

Web components that are

  • functional
  • truly reactive
  • strongly typed
function viewProfile(host: PipeFn<ShadowRoot>, {
  name = defAttr(''),
  photo = defAttr(''),
  age = defAttr(0),
}) {
  return host
  (img(cx`.profile-photo`)
    (attr('src', zip$`/${photo}`))
  )
  (div()
    (div(cx`.profile-name`)(name))
    (div(cx`.profile-age`)(age))
  )
  (button(zip$`Add ${name} to friends`))
}
const profile = customElement('mary-profile', viewProfile)

mount(document.body,
  (profile.new()
    (profile.prop('name', 'Mary'))
    (profile.prop('age', 9))

    (profile.prop('age', '9')) // type error
    (profile.prop('aage', 9)) // type error
  )
)

Typed Custom Events

type CounterDispatch =
  TypedDispatch<{ change: number }>

function viewCounter(host: PipeFn<ShadowRoot>, {
  count = defAttr(0),
}, dispatch: CounterDispatch) {
  count.sub(val => {
    host(dispatch('change', val))
    host(dispatch('change', val + '')) // type error
    host(dispatch('changeee', val)) // type error
  })
  return host
  (button(count)
    (on('click', () => count.v++))
  )
}

const counter = customElement('mary-counter', viewCounter)

counter.new()
  // typeof e = CustomEvent<number>
  // error: number is not assignable to string 🎉
  (counter.on('change', e => document.title = e.detail))
4.1.0

4 years ago

4.0.0

4 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.3.1

5 years ago

2.2.1

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago