Skip to main content

a python vesion vue/reactivity api

Project description

仿制VUE reactivity

目前仅支持自定义类和字符串、数字,无法监听数组等的变化,需要大佬帮助。

Usage

from reactivity import *

ref

effect(lambda: (print(v.value)))
v = ref(0)
v.value += 1 # 会自动触发注册的effect函数 

reactive

@dataclass
class Person:
    name: str
    age: int

effect(lambda: (print(obj.name) if obj.age else None))
obj = reactive(Person('wei', 21))
obj.name = 'waa' # 会自动触发注册的effect函数 

computed

v = ref(0)
# effect(lambda: (print(v.value)))
v.value += 1
ok = ref(0)
a = computed(lambda: v.value + 1 if ok.value else 999)
v.value += 1
v.value += 1
ok.value = 1
print(a.value)

#当ok.value被切换成1时,a.value会被自动更新成v.value + 1 而第1 、 2次v.value++都不会改变a.value的值。

参考

https://www.vuemastery.com/courses/vue-3-reactivity/vue3-reactivity

https://www.vuemastery.com/courses/vue3-deep-dive-with-evan-you/vue3-overview/

Vuejs设计与实现

https://github.com/cuixiaorui/mini-vue/tree/master/packages/reactivity/src

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reactivity-0.0.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

reactivity-0.0.2-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file reactivity-0.0.2.tar.gz.

File metadata

  • Download URL: reactivity-0.0.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for reactivity-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1131157e94616aff7e136eaaec0052697d2ec0471b283ce352598658072a1c00
MD5 47ea105f8bd3d82308abb9609cf6663b
BLAKE2b-256 7d4c837c1e31998ea62d699f28d6a5ddb32e6bdb17386390a3b9e6f5485088cc

See more details on using hashes here.

File details

Details for the file reactivity-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: reactivity-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for reactivity-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51cf65afc67d57f138c8124bdcba3a4a6a4c03d0dac4895d9735bed3dbd33aa8
MD5 778c80eff4989c1dc41e8f903c03cfd6
BLAKE2b-256 3bbc0370edf2402c3d812e6a3d040361ebc2a39d82a77fe99844a50d23f49299

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page