Toy Level Reactivity like Vue 3.x

Overview

reactivity

Reactivity like Vue 3.x

Features

  • Typescript JSX Support
  • Components and Fragment
  • Dependency-Collect Reactivity
  • Reactive Object based on ES6 Proxy
  • Ref and Computed Objects
  • Functional Component
  • Partly Composition API
  • Output Native DOM Node

Examples

info.name, () => info.age ], (old, newVal) => { console.log(old, newVal, "watch") }) const handleInputName = (ev: InputEvent) => { info.name = (ev.target as HTMLInputElement)?.value ?? "" } const handleInputAge = (ev: InputEvent) => { info.age = parseInt((ev.target as HTMLInputElement)?.value ?? "") } return ( <>

Hi, My name is {() => info.name /* Make it reactive */}. I'm {() => info.age} years old.

Name:

Age:

) }) const Count = defineComponent(() => { const count = ref(0) const handleClick = () => count.value += 1 return ( <>

Click times: {count}

) }) const Text = defineComponent<{ name: string }>((ctx) => (

{ctx.props.name}

)) const App = defineComponent(() => ( <> )) mount('#app', )">
import {
  defineComponent,
  reactive,
  mount,
  watch,
  ref,
} from './reactivity'

const NameInput = defineComponent(() => {
  
  const info = reactive<{
    name: string,
    age: number
  }>({
    name: "John",
    age: 20
  })

  watch([
    () => info.name,
    () => info.age
  ], (old, newVal) => {
    console.log(old, newVal, "watch")
  })

  const handleInputName = (ev: InputEvent) => {
    info.name = (ev.target as HTMLInputElement)?.value ?? ""
  }

  const handleInputAge = (ev: InputEvent) => {
    info.age = parseInt((ev.target as HTMLInputElement)?.value ?? "")
  }

  return (
    <>
      <p>Hi, My name is {() => info.name /* Make it reactive */}. I'm {() => info.age} years old.</p>
      <p>Name: <input 
          onInput={handleInputName}
          value={info.name /* This is not reactive */}
        />
      </p>
      <p>Age: <input 
          onInput={handleInputAge} 
          value={info.age}
        />
      </p>
    </>
  )
})

const Count = defineComponent(() => {
  const count = ref(0)
  const handleClick = () => count.value += 1

  return (
    <>
      <p>Click times: {count}</p>
      <button onClick={handleClick}>Click me! {count}</button>
    </>
  )
})

const Text = defineComponent<{
  name: string
}>((ctx) => (<h1>{ctx.props.name}</h1>))

const App = defineComponent(() => (
  <>
    <Text name="hello" />
    <Count />
    <NameInput />
  </>
))

mount('#app', <App />)

License

MIT License, Copyright (c) Hydrogen

You might also like...
Lightweight react-like library. Support for asynchronous rendering and hooks.

Recept · Lightweight react-like library. Like the name, this project is mainly based on the architectural idea of react, which can feel react more int

⚛️  🎥 3️⃣  A minimal boilerplate for Remotion + React Three Fiber
⚛️ 🎥 3️⃣ A minimal boilerplate for Remotion + React Three Fiber

Remotion + React Three Fiber Starter Template This is a template repository, click "Use this template" to create a repository based off this template!

⚛️  🎥 3️⃣  A minimal boilerplate for Remotion + React Three Fiber
⚛️ 🎥 3️⃣ A minimal boilerplate for Remotion + React Three Fiber

Remotion + React Three Fiber Starter Template This is a template repository, click "Use this template" to create a repository based off this template!

A toy virtual DOM diffing and reconciliation algorithm, with a simple event loop

A toy virtual DOM diffing and reconciliation algorithm, with a simple event loop

Toy video game project using PixiJS, React and Typescript

PixiJS space shooter This project was developed as a learning experience, to learn the basics of video game development using PixiJS as the graphics e

genji is A small vue state management framewok by vue3 reactivity.
genji is A small vue state management framewok by vue3 reactivity.

genji is A small vue state management framewok by vue3 reactivity. Why calls genji ? It's inspired by Overwatch. Genji flings prec

basic implementation of the Vue 3 reactivity engine - from scratch

Vue 3 Reactivity This material was created by Marc Backes in order to show how reactivity is solved in Vue 3. It contains a basic implementation of th

A reactive filesystem interface based on Vue 3 reactivity system.

A reactive filesystem interface based on Vue 3 reactivity system.

A mini version of Vue 3 with reactivity, runtime, and compiler modules

A mini version of Vue 3 with reactivity, runtime, and compiler modules

A pokemon-like project game where you level up by hacking your neighbor.

CTF BourgPalette A pokemon-like project game where you level up by hacking your neighbor. You play as a new hacker. You are not trying to capture all

🌩 A tiny (185 bytes) event-based Redux-like state manager for React, Preact, Angular, Vue, and Svelte

Storeon A tiny event-based Redux-like state manager for React, Preact, Angular, Vue and Svelte. Small. 180 bytes (minified and gzipped). No dependenci

Reactivity layer for Alpine 2.x

alpine-reactive This package provides a reactivity layer for Alpine 2.x. Problem When you create a component that uses a value defined outside of it,

A tiny ( 1KB) reactivity library

influer A tiny ( 1KB) reactivity library yarn add influer Introduction influer is a tiny reactivity library. Exported in ESM, CJS, and IIFE, all 1K

Meteor Reactivity for your React Native application :)

react-native-meteor Meteor-like methods for React Native. If you have questions, you can open a new issue in the repository or ask in the our Gitter c

Create reusable components with Alpine JS reactivity 🦑

Apline JS Component Alpine JS plugin x-component allows you to create reusable components, sprinkled with Alpine JS reactive data 🧁 Example 👀 Page W

Framework frontend Javascript yg dibuat untuk belajar lebih memahami tentang sistem reactivity pada framework2 frontend modern.

Fremwok-Fremwokan Framework frontend Javascript yg dibuat untuk belajar lebih memahami tentang sistem reactivity pada framework2 frontend modern. jika

Solidjs-meteor-data - Helpers for combining SolidJS and Meteor reactivity

solidjs-meteor-data This package provides helper functions for combining the rea

A high-performance framework with fine-grained observable-based reactivity for building rich applications

A high-performance framework with fine-grained observable-based reactivity for building rich applications

Owner
Hydrogen
Talk is cheap, show your code. @cladonia-cn
Hydrogen
A reactive filesystem interface based on Vue 3 reactivity system.

A reactive filesystem interface based on Vue 3 reactivity system.

Guillaume Chau 37 Oct 8, 2022
Reactivity layer for Alpine 2.x

alpine-reactive This package provides a reactivity layer for Alpine 2.x. Problem When you create a component that uses a value defined outside of it,

ARCHTECH 10 Oct 14, 2021
A tiny ( 1KB) reactivity library

influer A tiny (< 1KB) reactivity library yarn add influer Introduction influer is a tiny reactivity library. Exported in ESM, CJS, and IIFE, all < 1K

Tom Lienard 7 Jul 13, 2022
A lightweight reactivity API for other UI libraries to be built on top of.

This is a tiny (~850B minzipped) library for creating reactive observables via functions. You can use observables to store state, create computed properties (y = mx + b), and subscribe to updates as its value changes.

Maverick 533 Jan 2, 2023
Compile-time reactivity for JS

silmaril Compile-time reactivity for JS Install npm install --save silmaril yarn add silmaril pnpm add silmaril Features Compile-time reactivity Minim

Alexis H. Munsayac 27 Nov 10, 2022
React, React Native and Vue UI components for building data-driven apps with Elasticsearch

Reactive Search UI components library for Elasticsearch: Available for React, Vue and React Native Read how to build an e-commerce search UI a.) with

appbase.io 4.7k Jan 4, 2023
qiankun项目实践和优化(React+Vue)

qiankun项目实践和优化(React+Vue) 前言 qiankun微服务,将多个不同技术栈的系统(React,Vue,Angular,jQuery)等聚合成一个系统,各个系统又能各自独立部署运行,适用于大型团队和大型前端项目。 实现功能: 引入多技术栈(React + Vue) 后台管理系统(

Rick 30 Oct 31, 2022
A tiny state manager for React, Svelte, Vue and vanilla JS

dotto.x Dotto.x is a tiny state manager for React, Svelte, and vanilla JS. Lightweight. Core is less than 135 bytes (minified and gzipped). Zero depen

null 108 Nov 2, 2022
An event-based global state management tool for vue, react, mini-program, ect.

hy-event-store An event-based global state management tool for vue, react, mini-program, etc. 一个基于事件的全局状态管理工具,可以在Vue、React、小程序等任何地方使用。 设计灵感 在项目中找到一个更加

null 260 Jan 2, 2023
A library for react that can easily manipulate integers like adding a comma every 3 digits

A library for react that can easily manipulate integers like adding a comma every 3 digits

udinesia325 1 Nov 21, 2021