npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@glare-labs/vue-reflect-attribute

v0.0.1-pre.2

Published

_If there are any errors in the documentation, suggestions are welcome._

Downloads

15

Readme

@glare-labs/vue-reflect-attribute

If there are any errors in the documentation, suggestions are welcome.

Dynamically update data through the attributes of the observe HTMLElement object.

npm i @glare-labs/vue-reflect-attribute

<template>
  <div>
    <button ref="buttonRef">BUTTON</button>

    {{ disabledProp }}

    <button @click="handleClick">UPDATE</button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useReflectAttribute } from '@glare-labs/vue-reflect-attribute';

const buttonRef = ref<HTMLElement | null>(null)
const disabledProp = ref(false)

useReflectAttribute(buttonRef, {
  attributes: [
    { attribute: 'disabled', ref: disabledProp, reflect: true, type: 'boolean' },
  ]
})

const handleClick = () => {
  disabledProp.value = !disabledProp.value
}

</script>

Usage

This tool is very simple. Please use the following code example to understand the usage of the useReflectAttribute function:

<template>
  <div>
    <button id="target-button" ref="htmlElementRef">BUTTON</button>
    {{ disabledProp }}
    {{ selectedProp }}
    {{ textProp }}
    {{ paragraphProp }}
  </div>
</template>

<script setup lang="ts">
import { useReflectAttribute } from '@glare-labs/vue-reflect-attribute'
import { nextTick, onMounted, ref } from 'vue'

const htmlElementRef = ref<HTMLElement | null>(null)

const disabledProp = ref(false)
const selectedProp = ref(false)
const textProp = ref("default text")
const paragraphProp = ref("default text")

useReflectAttribute(htmlElementRef, {
  attributes: [
    { attribute: 'disabled',  ref: disabledProp,  reflect: true,  type: 'boolean' },
    { attribute: 'selected',  ref: selectedProp,  reflect: false, type: 'boolean' },
    { attribute: 'text',      ref: textProp,      reflect: true,  type: 'string' },
    { attribute: 'paragraph', ref: paragraphProp, reflect: false, type: 'string' },
  ],
  tick: 'before',
})

onMounted(() => {
  const button = document.querySelector('#target-button')

  button?.setAttribute('disabled', '')
  button?.setAttribute('selected', '')
  button?.setAttribute('text', 'NEW TEXT')
  button?.setAttribute('paragraph', 'NEW TEXT')

  nextTick(() => {
    console.log(`HTML: ${button?.hasAttribute('disabled')} DATA: ${disabledProp.value}`);
    console.log(`HTML: ${button?.hasAttribute('selected')} DATA: ${selectedProp.value}`);
    console.log(`HTML: ${button?.getAttribute('text')} DATA: ${textProp.value}`);
    console.log(`HTML: ${button?.getAttribute('paragraph')} DATA: ${paragraphProp.value}`);
  })

  /**
   * @output
   * HTML: true      DATA: true
   * HTML: true      DATA: false
   * HTML: NEW TEXT  DATA: NEW TEXT
   * HTML: NEW TEXT  DATA: default text
   */
})

</script>
<template>
  <div>
    <button id="target-button" ref="htmlElementRef">BUTTON</button>
    {{ disabledProp }}
    {{ selectedProp }}
    {{ textProp }}
    {{ paragraphProp }}
  </div>
</template>

<script setup lang="ts">
import { useReflectAttribute } from '@glare-labs/vue-reflect-attribute'
import { nextTick, onMounted, ref } from 'vue'

const htmlElementRef = ref<HTMLElement | null>(null)

const disabledProp = ref(false)
const selectedProp = ref(false)
const textProp = ref("default text")
const paragraphProp = ref("default text")

useReflectAttribute(htmlElementRef, {
  attributes: [
    { attribute: 'disabled',  ref: disabledProp,  reflect: true,  type: 'boolean' },
    { attribute: 'selected',  ref: selectedProp,  reflect: false, type: 'boolean' },
    { attribute: 'text',      ref: textProp,      reflect: true,  type: 'string' },
    { attribute: 'paragraph', ref: paragraphProp, reflect: false, type: 'string' },
  ],
  tick: 'after',
})

onMounted(() => {
  const button = document.querySelector('#target-button')

  button?.setAttribute('disabled', '')
  button?.setAttribute('selected', '')
  button?.setAttribute('text', 'NEW TEXT')
  button?.setAttribute('paragraph', 'NEW TEXT')

  nextTick(() => {
    console.log(`HTML: ${button?.hasAttribute('disabled')} DATA: ${disabledProp.value}`);
    console.log(`HTML: ${button?.hasAttribute('selected')} DATA: ${selectedProp.value}`);
    console.log(`HTML: ${button?.getAttribute('text')} DATA: ${textProp.value}`);
    console.log(`HTML: ${button?.getAttribute('paragraph')} DATA: ${paragraphProp.value}`);
  })

  /**
   * @output
   * HTML: false         DATA: false
   * HTML: false         DATA: false
   * HTML: default text  DATA: default text
   * HTML: default text  DATA: default text
   */
})

</script>

reflect option

The reflect option defaults to true.

When the reflect option value is true, data changes will update the attributes of HTMLElement, and changes in the attributes of HTMLElement will cause data updates.

attribute option

attribute specifies the attribute name of the target HTML element.

Example:

<template>
  <div>
    <button ref="htmlElementRef">{{ myRef }}</button>
  </div>
</template>

<script setup lang="ts">
import { useReflectAttribute } from '@glare-labs/vue-reflect-attribute'
import { ref } from 'vue'

const htmlElementRef = ref<HTMLElement | null>(null)

const myRef = ref("WoW")

useReflectAttribute(htmlElementRef, {
  attributes: [
    { attribute: 'my-wow', ref: myRef, reflect: true, type: 'string' },
  ]
})
</script>

Taking the above code as an example, if you modify the attribute my-wow of the button element in developer mode in the browser, the myRef responsive data will also be updated.

If I change it to MoM:

<button my-wow="MoM">MoM</button>
/**
 * @output
 * MoM
 */
console.log(myRef.value)

tick option

The tick option determines when useReflectAttribute performs data binding. The default value of tick is 'after', which means useReflectAttribute will perform data binding in nextTick of onMounted.

tick: 'before'

onMounted(() => {
  // ...
})

tick: 'after'

onMounted(() => {
  nextTick(() => {
    // ...
  })
})