0.2.0 • Published 4 years ago

@losmaquios/nova v0.2.0

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

Nova.js

Microframework for composable custom-elements

LosMaquios LosMaquios

Installation

$ npm install @losmaquios/nova

Example

import { 
  // Utils
  getElementInstance,

  // Composers
  attr, 
  prop,
  method,
  on,
  onConnected,
  onDisconnected,

  // Register functional custom element
  defineElement
} from '@losmaquios/nova'

function NovaButton () {
  const id = attr('id')
  const type = prop('type')

  const $element = getElementInstance()

  console.assert($element.tagName === 'button')

  const unwatchID = id.watch((oldID, newID) => {
    // ...
    console.assert(id.value === newID)
    unwatchID()
  })

  const unwatchType = type.watch((oldType, newType) => {
    // ...
    console.assert(type.value === newType)
    unwatchType()
  })

  const offOnConnected = onConnected(() => {
    console.log('Connected callback')
  })

  const offOnDisconnected = onDisconnected(() => {
    console.log('Disconnected callback')
  })

  function doSomething () {
    console.log('Doing something')
  }

  const doSomething = method('doSomething', doSomething)

  method(doSomething)

  const doSomething2 = method('doSomething') // Get method

  const offClick = on('click', () => {
    doSomething()
    offClick()
  })
}

defineElement(NovaButton, { 
  tag: 'nova-button',
  type: 'button' 
})
const $novaButton = document.createElement('nova-button')

$novaButton.setAttribute('id', 'some-id')
$novaButton.type = 'primary'

$novaButton.doSomething()
$novaButton.click()
0.2.0

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago