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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@actview/core

v1.0.3

Published

Core reactive system for Actview - ref, reactive, computed, watch, compile

Downloads

23

Readme

@actview/core

Actview 的核心响应式系统,提供 Vue 风格的响应式 API。

安装

npm install @actview/core
# 或
pnpm add @actview/core

API

ref<T>(value: T): Ref<T>

创建一个响应式引用,通过 .value 访问和修改值。

import { ref } from '@actview/core'

const count = ref(0)
console.log(count.value) // 0

count.value++
console.log(count.value) // 1

reactive<T>(value: T): T

创建一个响应式对象,支持深层响应式和数组。

import { reactive } from '@actview/core'

const state = reactive({
  name: 'Actview',
  items: [1, 2, 3]
})

state.name = 'New Name'  // 触发更新
state.items.push(4)      // 触发更新

computed<T>(getter: () => T): Ref<T>

创建一个计算属性,依赖变化时自动重新计算。

import { ref, computed } from '@actview/core'

const count = ref(1)
const double = computed(() => count.value * 2)

console.log(double.value) // 2

count.value = 5
console.log(double.value) // 10

watch<T>(source, callback)

监听响应式数据变化,支持 refreactive 对象或 getter 函数。

import { ref, watch } from '@actview/core'

const count = ref(0)

// 监听 ref
watch(count, (newVal, oldVal) => {
  console.log(`count changed: ${oldVal} -> ${newVal}`)
})

// 监听 getter 函数
watch(
  () => count.value * 2,
  (newVal, oldVal) => {
    console.log(`double changed: ${oldVal} -> ${newVal}`)
  }
)

watchEffect(callback: () => void)

立即执行回调函数,并自动追踪依赖,依赖变化时重新执行。

import { ref, watchEffect } from '@actview/core'

const count = ref(0)

watchEffect(() => {
  console.log(`count is: ${count.value}`)
})
// 立即输出: count is: 0

count.value = 1
// 输出: count is: 1

compile(option: Option)

配置驱动的 DOM 绑定,通过选择器自动绑定数据和事件。

import { ref, compile } from '@actview/core'

const visible = ref(true)
const message = ref('Hello')

compile({
  selector: '#app',
  show: () => visible.value,
  text: () => message.value,
  listeners: [
    { type: 'click', callback: () => visible.value = !visible.value }
  ]
})

Option 配置项

| 属性 | 类型 | 说明 | |------|------|------| | selector | string | jQuery 选择器 | | show | boolean \| () => boolean | 控制元素显示/隐藏 | | text | string \| () => string | 设置元素文本内容 | | render | () => string \| Node | 自定义渲染函数(支持 JSX) | | listeners | Listener[] | 事件监听器列表 |

类型定义

// 响应式引用
type Ref<T> = {
  value: T
  __isRef: true
}

// 事件监听器(类型安全)
type Listener<K extends keyof HTMLElementEventMap> = {
  type: K
  callback: (e: HTMLElementEventMap[K]) => void
}

// compile 配置
type Option = {
  selector: string
  show?: boolean | (() => boolean)
  text?: string | (() => string)
  listeners?: Listener[]
  render?: () => string | HTMLElement | Text | DocumentFragment
}

依赖

  • jquery ^4.0.0

License

MIT