observ:观察:eye:-Vue.js计算属性和观察程序的Python端口

  • t8_811137
    了解作者
  • 11.3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-02 08:26
    上传日期
观察 :eye: Observ是的程序的Python端口。 它完全与事件循环/框架无关,并且没有依赖关系,因此可以在面向Python> = 3.6的任何项目中使用。 Observ为有状态应用程序提供了以下两个好处: 您不再需要手动使状态无效并重新计算状态(例如,通过脏标志): 计算状态自动失效 懒惰地重新计算了计算状态 您可以对状态变化(无论是否计算)做出React,从而启用单向流: 状态更改导致视图更改(例如,状态更改回调更新了UI小部件) 视图触发输入事件(例如,UI中触发了鼠标事件) 输入事件导致状态更改(例如,鼠标事件会更新状态) 原料药 from observ import observe, computed, watch state = observe(state) 观察字典,列表,元组和集合的嵌套结构。 返回状态输入对象的可观察的克隆。 watcher = wat
observ-master.zip
  • observ-master
  • .gitignore
    58B
  • pyproject.toml
    606B
  • LICENSE
    1KB
  • observ
  • __init__.py
    10.2KB
  • setup.cfg
    280B
  • .github
  • workflows
  • ci.yml
    1016B
  • examples
  • observe_qt.py
    2KB
  • README.md
    2KB
  • tests
  • test_observe.py
    1.1KB
  • test_collections.py
    7.9KB
  • test_deps.py
    999B
  • test_usage.py
    2.8KB
  • scripts.py
    438B
内容介绍
[![PyPI version](https://badge.fury.io/py/observ.svg)](https://badge.fury.io/py/observ) [![CI status](https://github.com/Korijn/observ/workflows/CI/badge.svg)](https://github.com/Korijn/observ/actions) # Observ ���� Observ is a Python port of [Vue.js](https://vuejs.org/)' [computed properties and watchers](https://vuejs.org/v2/guide/computed.html). It is completely event loop/framework agnostic and has no dependencies so it can be used in any project targeting Python >= 3.6. Observ provides the following two benefits for stateful applications: 1) You no longer need to manually invalidate and recompute state (e.g. by dirty flags): * computed state is invalidated automatically * computed state is lazily re-evaluated 2) You can react to changes in state (computed or not), enabling unidirectional flow: * _state changes_ lead to _view changes_ (e.g. a state change callback updates a UI widget) * the _view_ triggers _input events_ (e.g. a mouse event is triggered in the UI) * _input events_ lead to _state changes_ (e.g. a mouse event updates the state) ## API `from observ import observe, computed, watch` * `state = observe(state)` Observe nested structures of dicts, lists, tuples and sets. Returns an observable clone of the state input object. * `watcher = watch(func, callback, deep=False, immediate=False)` React to changes in the state accessed in `func` with `callback(old_value, new_value)`. Returns a watcher object. `del`elete it to disable the callback. * `wrapped_func = computed(func)` Define computed state based on observable state with `func` and recompute lazily. Returns a wrapped copy of the function which only recomputes the output if any of the state it depends on becomes dirty. Can be used as a function decorator. ## Quick start and example Install observ with pip/pipenv/poetry: `pip install observ` Check out [`examples/observe_qt.py`](https://github.com/Korijn/observ/blob/master/examples/observe_qt.py) for a simple example using observ.
评论
    相关推荐